{"thread":{"id":"32919","subject":"git clone combined with --depth, --branch and --single-branch","startedAt":"2013-02-17T12:29:17Z","lastAt":"2013-02-17T19:10:37Z","messageCount":4,"participants":["Thibault Kruse","Duy Nguyen"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"209597","messageId":"CAByu6UWNZLrtwo+FUeq2OELoX3jo1Qng9amko36JGa5pq+y11A@mail.gmail.com","threadId":"32919","inReplyTo":null,"subject":"git clone combined with --depth, --branch and --single-branch","fromName":"Thibault Kruse","fromEmail":"tibokruse@googlemail.com","sentAt":"2013-02-17T12:29:17Z","receivedAt":"2013-02-17T12:29:17Z","isPatch":false,"sender":{"key":"tibokruse@googlemail.com","avatar":"https://gravatar.com/avatar/68c46b980bae1554690b4e334db8e5102b7fc25afae6bba2fdf48ce1243cc0c6?d=mp&s=160"},"body":"Hi all,\n\nUsing git 1.7.10.4\n\nI find the behavior or documentation of \"git clone  --single-branch\"\nconfusing. Docs currently say:\n\nman git-clone\n\n       --single-branch\n           Clone only the history leading to the tip of a single\nbranch, either specified by the --branch option or the primary branch\nremote�<80><99>s HEAD points\n           at. When creating a shallow clone with the --depth option,\nthis is the default, unless --no-single-branch is given to fetch the\nhistories near\n           the tips of all branches.\n\nbased onthis documentation, I cannot understand any of the results I\nget when combining --depth and --singe-branch.\n\nI start with this repo1 (for how to createin linux, see bottom):\n\ngit log --pretty=format:'%h-%s %d' --graph --decorate  --all\n* 4565162-5  (foo)\n* 20ce846-4\n* a0615eb-3\n* fa4131d-2\n* f0683bd-1  (bar)\n| * 432b5ec-m1  (HEAD, master)\n|/\n* 39df203-0\n\ngit clone repo1 repo2 --depth 1\ncd repo2\ngit log --pretty=format:'%h-%s %d' --graph --decorate  --all\n* 432b5ec-m1  (HEAD, origin/master, origin/HEAD, master)\n* 39df203-0\n\n# Why are branches \"foo\" and \"bar\" missing?\n\ncd ..\ngit clone repo1 repo3 --depth 1 --branch foo\ngit log --pretty=format:'%h-%s %d' --graph --decorate  --all\n* 4565162-5  (HEAD, origin/foo, foo)\n* 20ce846-4\n* a0615eb-3\n* fa4131d-2\n* f0683bd-1\n| * 432b5ec-m1  (origin/master, origin/HEAD)\n|/\n* 39df203-0\n\n# Why is --depth not having effect, and why is branch bar not there,\nyet master is?\n\ncd ..\ngit clone repo1 repo4 --depth 1 --branch foo --single-branch\ngit log --pretty=format:'%h-%s %d' --graph --decorate  --all\n* 4565162-5  (HEAD, origin/foo, foo)\n* 20ce846-4\n* a0615eb-3\n* fa4131d-2\n* f0683bd-1\n| * 432b5ec-m1  (origin/master, origin/HEAD)\n|/\n* 39df203-0\n\n# Why is --depth not having effect, and why is branch master still there?\n\n###################################\n# Okay, so --depth seems to generally not work when cloning locally.\nSo maybe when doing so from github:\n\ngit clone https://github.com/git/git --depth 1\ncd git\ngit log --pretty=format:'%h-%s %d' --graph --decorate  --all\n* 7b6e784-Update draft release notes to 1.8.2  (HEAD, origin/master,\norigin/HEAD, master)\n* 17e45f8-Merge branch\n'wk/man-deny-current-branch-is-default-these-days'  (grafted)\ngit branch -a\n* master\n  remotes/origin/HEAD -> origin/master\n  remotes/origin/master\ngit tag\n>\n\n# Why don't other branches appear here?\n# Hm, I'll add \"--branch master\" to the command\n\ngit clone https://github.com/git/git git3 --depth 1 --branch master\ncd git3\ngit branch -a\n* master\n  remotes/origin/HEAD -> origin/master\n  remotes/origin/master\n  remotes/origin/next\n  remotes/origin/pu\n  remotes/origin/todo\ngit tag\n> gitgui-0.10.0\n> gitgui-0.10.1\n> gitgui-0.10.2\n> ...\n\n# And why DO they appear here? Why do I now get all tags?\n# Same result for --branch next\n# okay, let's try adding --single-branch\n\ngit clone https://github.com/git/git git4 --depth 1 --branch next\n--single-branch\ncd git4\ngit branch -a\n* next\n  remotes/origin/next\n  remotes/origin/pu\n  remotes/origin/todo\n\n# Now I don't get master, but I still get those other branches??? And also tags?\n\n\nNow I am aware that a bug was fixed in git 1.8.0:\nhttps://raw.github.com/gitster/git/master/Documentation/RelNotes/1.8.0.txt\n\n * A repository created with \"git clone --single\" had its fetch\n   refspecs set up just like a clone without \"--single\", leading the\n   subsequent \"git fetch\" to slurp all the other branches, defeating\n   the whole point of specifying \"only this branch\".\n\n\nBut even considering that bug (and assuming it also affected git clone),\nthe results I get for 1.7.10.4 seem all weird, and not really\nfollowing the documentation.\n\n\nSo I am sorry I cannot phrase this as a single question, as the\nresults are not consistent with each other or the documentation, and\nthose results seem to be related.\n\ncheers,\n  Thibault Kruse\n\n\n\n\nHow to create local repo1:\n\nmkdir repo1\ncd repo1\ngit init\necho 0 >> foo.txt\ngit add foo.txt\ngit commit -m 0\ngit co master -b bar\necho 1 >> bar.txt\ngit add bar.txt\ngit commit -m 1\ngit co bar -b foo\necho 2 >> foo.txt\ngit add foo.txt\ngit commit -m 2\necho 3 >> foo.txt\ngit add foo.txt\ngit commit -m 3\necho 4 >> foo.txt\ngit add foo.txt\ngit commit -m 4\necho 5 >> foo.txt\ngit add foo.txt\ngit commit -m 5\ngit co master\necho 1 > master.txt\ngit add master.txt\ngit commit -m m1\n"},{"id":"209600","messageId":"CACsJy8C5G7yy=KDtdsE-9aYTdSEO3v=-25WKtGnLALshXnE+uQ@mail.gmail.com","threadId":"32919","inReplyTo":"CAByu6UWNZLrtwo+FUeq2OELoX3jo1Qng9amko36JGa5pq+y11A@mail.gmail.com","subject":"Re: git clone combined with --depth, --branch and --single-branch","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2013-02-17T14:32:55Z","receivedAt":"2013-02-17T14:32:55Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sun, Feb 17, 2013 at 7:29 PM, Thibault Kruse\n<tibokruse@googlemail.com> wrote:\n> git log --pretty=format:'%h-%s %d' --graph --decorate  --all\n> * 4565162-5  (foo)\n> * 20ce846-4\n> * a0615eb-3\n> * fa4131d-2\n> * f0683bd-1  (bar)\n> | * 432b5ec-m1  (HEAD, master)\n> |/\n> * 39df203-0\n>\n> git clone repo1 repo2 --depth 1\n> cd repo2\n> git log --pretty=format:'%h-%s %d' --graph --decorate  --all\n> * 432b5ec-m1  (HEAD, origin/master, origin/HEAD, master)\n> * 39df203-0\n>\n> # Why are branches \"foo\" and \"bar\" missing?\n\n--depth implies --single-branch. Without explicit --branch,\n--single-branch will fetch HEAD. You need --no-single-branch to get\nfoo and bar.\n\n> cd ..\n> git clone repo1 repo3 --depth 1 --branch foo\n> git log --pretty=format:'%h-%s %d' --graph --decorate  --all\n> * 4565162-5  (HEAD, origin/foo, foo)\n> * 20ce846-4\n> * a0615eb-3\n> * fa4131d-2\n> * f0683bd-1\n> | * 432b5ec-m1  (origin/master, origin/HEAD)\n> |/\n> * 39df203-0\n>\n> # Why is --depth not having effect, and why is branch bar not there,\n> yet master is?\n\nI'm not sure, but I can't reproduce it. There's an unreleased fix in\ndepth calculation (682c7d2 (upload-pack: fix off-by-one depth\ncalculation in shallow clone - 2013-01-11) that might affect this. You\nmay want to try again with \"master\". I got this with the same command\n\n* edbd6cb (grafted, HEAD, origin/foo, foo) 5\n-- \nDuy\n"},{"id":"209604","messageId":"CAByu6UWw-6ssEug-Fm1t7_L2jVuC-KMh-NC=kzxfum=r6X5VcQ@mail.gmail.com","threadId":"32919","inReplyTo":"CACsJy8C5G7yy=KDtdsE-9aYTdSEO3v=-25WKtGnLALshXnE+uQ@mail.gmail.com","subject":"Re: git clone combined with --depth, --branch and --single-branch","fromName":"Thibault Kruse","fromEmail":"tibokruse@googlemail.com","sentAt":"2013-02-17T17:46:31Z","receivedAt":"2013-02-17T17:46:31Z","isPatch":false,"sender":{"key":"tibokruse@googlemail.com","avatar":"https://gravatar.com/avatar/68c46b980bae1554690b4e334db8e5102b7fc25afae6bba2fdf48ce1243cc0c6?d=mp&s=160"},"body":"Hi Duy,\n\nOn Sun, Feb 17, 2013 at 3:32 PM, Duy Nguyen <pclouds@gmail.com> wrote:\n> On Sun, Feb 17, 2013 at 7:29 PM, Thibault Kruse\n> <tibokruse@googlemail.com> wrote:\n>> git log --pretty=format:'%h-%s %d' --graph --decorate  --all\n>> * 4565162-5  (foo)\n>> * 20ce846-4\n>> * a0615eb-3\n>> * fa4131d-2\n>> * f0683bd-1  (bar)\n>> | * 432b5ec-m1  (HEAD, master)\n>> |/\n>> * 39df203-0\n>>\n>> git clone repo1 repo2 --depth 1\n>> cd repo2\n>> git log --pretty=format:'%h-%s %d' --graph --decorate  --all\n>> * 432b5ec-m1  (HEAD, origin/master, origin/HEAD, master)\n>> * 39df203-0\n>>\n>> # Why are branches \"foo\" and \"bar\" missing?\n>\n> --depth implies --single-branch. Without explicit --branch,\n> --single-branch will fetch HEAD. You need --no-single-branch to get\n> foo and bar.\n\nAgreed, sorry. I forgot that --depth implied --single-branch. Probably\nbecause it don't like that being a default that breaks behavior to\nversions that did not have the --single-branch feature.\nSo this example is the only one which I agree does actually what can\nbe expected from the documentation (with respect to branches. --depth\nalso does not restrict the history length, but the example does not\nshow it).\n\n>> cd ..\n>> git clone repo1 repo3 --depth 1 --branch foo\n>> git log --pretty=format:'%h-%s %d' --graph --decorate  --all\n>> * 4565162-5  (HEAD, origin/foo, foo)\n>> * 20ce846-4\n>> * a0615eb-3\n>> * fa4131d-2\n>> * f0683bd-1\n>> | * 432b5ec-m1  (origin/master, origin/HEAD)\n>> |/\n>> * 39df203-0\n>>\n>> # Why is --depth not having effect, and why is branch bar not there,\n>> yet master is?\n>\n> I'm not sure, but I can't reproduce it.\n\nDo you mean you cannot reproduce with 1.7.10.4?\n\n\nSo far I used ubuntu packaged versions, Here is what I got with master:\ngit --version\ngit version 1.8.1.3.619.g7b6e784\n# added commit m2 and m3 to master branch in repo1 to show that\n--depth is not working locally\ngit clone repo1 repo2 --depth 1\ngit log --pretty=format:'%h-%s %d' --graph --decorate  --all\n* 704f0c4-m3  (HEAD, origin/master, origin/HEAD, master)\n* 7b90b28-m2\n* 1fa92bd-m1\n* 5da3517-0\n\nSo I still get the --depth not having affect locally, but I confirm\nall other cases I posted work as expected with 1.8.1.3.619.g7b6e784.\nMeaning --depth works from a remote repo, and --single-branch (implied\nby depth) really just creates that branch locally.\n\nI don't even know where to start looking for why --depth has no effect\nfor disk-local remotes.\nI don't have the git command aliased, and in repo1, I get:\nalias.br=branch\nalias.co=checkout\nalias.ci=commit\nalias.di=diff\nalias.st=status\nalias.mt=mergetool\nalias.pr=pull --rebase\nalias.ri=rebase --interactive\nalias.sa=stash apply\nalias.c-p=cherry-pick\nalias.lg=!git log --pretty=format:%h%x09%an%x09%ad%x09%s\nalias.lgg=log --graph --pretty=format:'%Cred%h%Creset\n-%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\n--abbrev-commit --date=relative\nalias.top=!eval cd $(pwd)/$(git rev-parse --show-cdup) && pwd\ncore.excludesfile=/home/kruset/.bashconfig/gitignore.global\ncore.repositoryformatversion=0\ncore.filemode=true\ncore.bare=false\ncore.logallrefupdates=true\n\nNot sure whether any of the \"core\" properties can cause this.\n"},{"id":"209606","messageId":"CAByu6UV+M76tcHPR4NqotiU=Fag-=sQFxyTOu3evhw+nRxQGhA@mail.gmail.com","threadId":"32919","inReplyTo":"CAByu6UVR7k-d8PkqhHBG-A1zTCETemjhch0OA7i6_56yBV_YyQ@mail.gmail.com","subject":"Fwd: git clone combined with --depth, --branch and --single-branch","fromName":"Thibault Kruse","fromEmail":"tibokruse@googlemail.com","sentAt":"2013-02-17T19:10:37Z","receivedAt":"2013-02-17T19:10:37Z","isPatch":false,"sender":{"key":"tibokruse@googlemail.com","avatar":"https://gravatar.com/avatar/68c46b980bae1554690b4e334db8e5102b7fc25afae6bba2fdf48ce1243cc0c6?d=mp&s=160"},"body":"Actually, using git 1.8.3, I get:\n\ngit clone repo1 repo2 --depth 1\nwarning: --depth is ignored in local clones; use file:// instead.\n...\n\nSo I guess the warning says it all, it helps to read it.\n"}]}