{"thread":{"id":"41135","subject":"Questions on passing --depth to git-clone vs. git-fetch","startedAt":"2016-01-06T12:30:19Z","lastAt":"2016-01-13T18:24:07Z","messageCount":9,"participants":["Sebastian Schuberth","Duy Nguyen","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"275432","messageId":"n6j1cs$p4$1@ger.gmane.org","threadId":"41135","inReplyTo":null,"subject":"Questions on passing --depth to git-clone vs. git-fetch","fromName":"Sebastian Schuberth","fromEmail":"sschuberth@gmail.com","sentAt":"2016-01-06T12:30:19Z","receivedAt":"2016-01-06T12:30:19Z","isPatch":false,"sender":{"key":"sschuberth@gmail.com","avatar":"https://avatars.githubusercontent.com/u/349154?v=4"},"body":"Hi,\n\nI recently compared the results of doing\n\n    $ git clone --depth=1 https://github.com/git/git.git git-clone-depth-1\n\nversus\n\n    $ mkdir git-fetch-depth-1\n    $ cd git-fetch-depth-1\n    $ git init\n    $ git remote add origin https://github.com/git/git.git\n    $ git fetch --depth=1\n\nand noticed a few things:\n\n1. The docs of clone [1] say about --depth \"Create a shallow clone with a history truncated to the specified number of revisions\" while for fetch the docs [2] say \"[...] to the specified number of commits [...]\". As in this particular case revision are always commits, I think the clone docs should also say \"commits\".\n\n2. In the fetch docs --depth is described to \"Deepen or shorten the history of a shallow repository created by git clone\". That sounds as if my example from above where I initialze a repo manually would not allow fetch to be called with --depth as I did not clone before. But in fact my example works fine. I guess we need some clarfication in the wording here.\n\n3. When running \"git log --all -oneline\" in the two working trees I get different results, which is not what I'd expect:\n\n    $ cd git-clone-depth-1\n    $ git log --all --oneline\n      7548842 Git 2.7\n\nversus\n\n    $ cd git-fetch-depth-1\n    $ git log --all --oneline\n      b819526 Merge branch 'jk/notes-merge-from-anywhere' into pu\n      e2281f4 What's cooking (2016/01 #01)\n      ef7b32d Sync with 2.7\n      7548842 Git 2.7\n      833e482 Git 2.6.5\n\nSo in the clone case only the specified number of commits from the tip of the default branch (master in this case) is fetched, not of each remote branch history. fetch in the other hand really gets the specified number of commits from the tip of each remote branch history. I don't know whether this behavior is inded or not as I cannot find any docs on it either way. But it seems inconsistent to me that clone with --depth only gets the history for the default branch, as clone without --depth would give me the history of all branches.\n\nFor completeness, I'm using Git for Windows 2.7.\n\nAny comments?\n\n[1] https://git-scm.com/docs/git-clone\n[1] https://git-scm.com/docs/git-fetch\n\n-- \nSebastian Schuberth\n"},{"id":"275433","messageId":"CACsJy8D5DeDOCd1tn876s3+2fBR6e-X1UANkAeiw8tzAeDcDng@mail.gmail.com","threadId":"41135","inReplyTo":"n6j1cs$p4$1@ger.gmane.org","subject":"Re: Questions on passing --depth to git-clone vs. git-fetch","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2016-01-06T12:41:55Z","receivedAt":"2016-01-06T12:41:55Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Wed, Jan 6, 2016 at 7:30 PM, Sebastian Schuberth\n<sschuberth@gmail.com> wrote:\n> Hi,\n>\n> I recently compared the results of doing\n>\n>     $ git clone --depth=1 https://github.com/git/git.git git-clone-depth-1\n>\n> versus\n>\n>     $ mkdir git-fetch-depth-1\n>     $ cd git-fetch-depth-1\n>     $ git init\n>     $ git remote add origin https://github.com/git/git.git\n>     $ git fetch --depth=1\n>\n> and noticed a few things:\n\nI think the culprit is the \"git remote add\" line. \"git clone --depth\"\nby default will fetch only one branch (aka --single-branch option in\ngit-clone). But I suspect when you add a new remote, the default\nrefspec is to get all refs. So \"git fetch --depth=1\" means fetch _all_\nrefs, each one has maximum one commit. \"git log --graph --decorate\"\nshould show this clearer.\n\n> 1. The docs of clone [1] say about --depth \"Create a shallow clone with a history truncated to the specified number of revisions\" while for fetch the docs [2] say \"[...] to the specified number of commits [...]\". As in this particular case revision are always commits, I think the clone docs should also say \"commits\".\n>\n> 2. In the fetch docs --depth is described to \"Deepen or shorten the history of a shallow repository created by git clone\". That sounds as if my example from above where I initialze a repo manually would not allow fetch to be called with --depth as I did not clone before. But in fact my example works fine. I guess we need some clarfication in the wording here.\n>\n> 3. When running \"git log --all -oneline\" in the two working trees I get different results, which is not what I'd expect:\n>\n>     $ cd git-clone-depth-1\n>     $ git log --all --oneline\n>       7548842 Git 2.7\n>\n> versus\n>\n>     $ cd git-fetch-depth-1\n>     $ git log --all --oneline\n>       b819526 Merge branch 'jk/notes-merge-from-anywhere' into pu\n>       e2281f4 What's cooking (2016/01 #01)\n>       ef7b32d Sync with 2.7\n>       7548842 Git 2.7\n>       833e482 Git 2.6.5\n>\n> So in the clone case only the specified number of commits from the tip of the default branch (master in this case) is fetched, not of each remote branch history. fetch in the other hand really gets the specified number of commits from the tip of each remote branch history. I don't know whether this behavior is inded or not as I cannot find any docs on it either way. But it seems inconsistent to me that clone with --depth only gets the history for the default branch, as clone without --depth would give me the history of all branches.\n>\n> For completeness, I'm using Git for Windows 2.7.\n>\n> Any comments?\n>\n> [1] https://git-scm.com/docs/git-clone\n> [1] https://git-scm.com/docs/git-fetch\n>\n> --\n> Sebastian Schuberth\n>\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n\n\n\n-- \nDuy\n"},{"id":"275436","messageId":"568D10D6.7020707@gmail.com","threadId":"41135","inReplyTo":"CACsJy8D5DeDOCd1tn876s3+2fBR6e-X1UANkAeiw8tzAeDcDng@mail.gmail.com","subject":"Re: Questions on passing --depth to git-clone vs. git-fetch","fromName":"Sebastian Schuberth","fromEmail":"sschuberth@gmail.com","sentAt":"2016-01-06T13:04:22Z","receivedAt":"2016-01-06T13:04:22Z","isPatch":false,"sender":{"key":"sschuberth@gmail.com","avatar":"https://avatars.githubusercontent.com/u/349154?v=4"},"body":"On 1/6/2016 13:41, Duy Nguyen wrote:\n\n> I think the culprit is the \"git remote add\" line. \"git clone --depth\"\n> by default will fetch only one branch (aka --single-branch option in\n> git-clone). But I suspect when you add a new remote, the default\n\nNow that you mention it I see this being documented as part of \n--single-branch instead of --depth, which I think is confusing. I'll \nsend a patch.\n\n-- \nSebastian Schuberth\n"},{"id":"275437","messageId":"568D1167.30700@gmail.com","threadId":"41135","inReplyTo":"568D10D6.7020707@gmail.com","subject":"[PATCH] docs: clarify that passing --depth to git-clone implies --single-branch","fromName":"Sebastian Schuberth","fromEmail":"sschuberth@gmail.com","sentAt":"2016-01-06T13:06:47Z","receivedAt":"2016-01-06T13:06:47Z","isPatch":true,"sender":{"key":"sschuberth@gmail.com","avatar":"https://avatars.githubusercontent.com/u/349154?v=4"},"body":"It is confusing to document how --depth behaves as part of the\n--single-branch docs. Better move that part to the --depth docs, saying\nthat it implies --single-branch by default.\n\nSigned-off-by: Sebastian Schuberth <sschuberth@gmail.com>\n---\n Documentation/git-clone.txt | 9 ++++-----\n 1 file changed, 4 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt\nindex 6bf000d..943de8b 100644\n--- a/Documentation/git-clone.txt\n+++ b/Documentation/git-clone.txt\n@@ -190,15 +190,14 @@ objects from the source repository into a pack in the cloned repository.\n \n --depth <depth>::\n \tCreate a 'shallow' clone with a history truncated to the\n-\tspecified number of revisions.\n+\tspecified number of revisions. Implies `--single-branch` unless\n+\t`--no-single-branch` is given to fetch the histories near the\n+\ttips of all branches.\n \n --[no-]single-branch::\n \tClone only the history leading to the tip of a single branch,\n \teither specified by the `--branch` option or the primary\n-\tbranch remote's `HEAD` points at. When creating a shallow\n-\tclone with the `--depth` option, this is the default, unless\n-\t`--no-single-branch` is given to fetch the histories near the\n-\ttips of all branches.\n+\tbranch remote's `HEAD` points at.\n \tFurther fetches into the resulting repository will only update the\n \tremote-tracking branch for the branch this option was used for the\n \tinitial cloning.  If the HEAD at the remote did not point at any\n-- \n2.7.0.windows.1\n"},{"id":"275496","messageId":"xmqqmvsh41j3.fsf@gitster.mtv.corp.google.com","threadId":"41135","inReplyTo":"568D1167.30700@gmail.com","subject":"Re: [PATCH] docs: clarify that passing --depth to git-clone implies --single-branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-01-07T19:45:04Z","receivedAt":"2016-01-07T19:45:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sebastian Schuberth <sschuberth@gmail.com> writes:\n\n> It is confusing to document how --depth behaves as part of the\n> --single-branch docs. Better move that part to the --depth docs, saying\n> that it implies --single-branch by default.\n>\n> Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>\n> ---\n\nYeah, the new organization is much easier and intuitive to follow.\n\nThanks.\n\n\n>  Documentation/git-clone.txt | 9 ++++-----\n>  1 file changed, 4 insertions(+), 5 deletions(-)\n>\n> diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt\n> index 6bf000d..943de8b 100644\n> --- a/Documentation/git-clone.txt\n> +++ b/Documentation/git-clone.txt\n> @@ -190,15 +190,14 @@ objects from the source repository into a pack in the cloned repository.\n>  \n>  --depth <depth>::\n>  \tCreate a 'shallow' clone with a history truncated to the\n> -\tspecified number of revisions.\n> +\tspecified number of revisions. Implies `--single-branch` unless\n> +\t`--no-single-branch` is given to fetch the histories near the\n> +\ttips of all branches.\n>  \n>  --[no-]single-branch::\n>  \tClone only the history leading to the tip of a single branch,\n>  \teither specified by the `--branch` option or the primary\n> -\tbranch remote's `HEAD` points at. When creating a shallow\n> -\tclone with the `--depth` option, this is the default, unless\n> -\t`--no-single-branch` is given to fetch the histories near the\n> -\ttips of all branches.\n> +\tbranch remote's `HEAD` points at.\n>  \tFurther fetches into the resulting repository will only update the\n>  \tremote-tracking branch for the branch this option was used for the\n>  \tinitial cloning.  If the HEAD at the remote did not point at any\n"},{"id":"275524","messageId":"568F7EDD.9020003@gmail.com","threadId":"41135","inReplyTo":"n6j1cs$p4$1@ger.gmane.org","subject":"[PATCH] docs: say \"commits\" in the --depth option wording for git-clone","fromName":"Sebastian Schuberth","fromEmail":"sschuberth@gmail.com","sentAt":"2016-01-08T09:18:21Z","receivedAt":"2016-01-08T09:18:21Z","isPatch":true,"sender":{"key":"sschuberth@gmail.com","avatar":"https://avatars.githubusercontent.com/u/349154?v=4"},"body":"It is not wrong to talk about \"revisions\" here, but in this context\nrevisions are always commits, and that is how we already name it in the\ngit-fetch docs. So align the docs by always referring to \"commits\".\n---\n Documentation/git-clone.txt | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt\nindex 943de8b..789b668 100644\n--- a/Documentation/git-clone.txt\n+++ b/Documentation/git-clone.txt\n@@ -190,7 +190,7 @@ objects from the source repository into a pack in the cloned repository.\n \n --depth <depth>::\n \tCreate a 'shallow' clone with a history truncated to the\n-\tspecified number of revisions. Implies `--single-branch` unless\n+\tspecified number of commits. Implies `--single-branch` unless\n \t`--no-single-branch` is given to fetch the histories near the\n \ttips of all branches.\n \n-- \n2.7.0.windows.1\n"},{"id":"275525","messageId":"568F8244.2030309@gmail.com","threadId":"41135","inReplyTo":"n6j1cs$p4$1@ger.gmane.org","subject":"[PATCH] docs: clarify that --depth for git-fetch works with newly initialized repos","fromName":"Sebastian Schuberth","fromEmail":"sschuberth@gmail.com","sentAt":"2016-01-08T09:32:52Z","receivedAt":"2016-01-08T09:32:52Z","isPatch":true,"sender":{"key":"sschuberth@gmail.com","avatar":"https://avatars.githubusercontent.com/u/349154?v=4"},"body":"The original wording sounded as if --depth could only be used to deepen or\nshorten the history of existing repos. However, that is not the case. In a\nworkflow like\n\n    $ git init\n    $ git remote add origin https://github.com/git/git.git\n    $ git fetch --depth=1\n\nThe newly initialized repo is properly created as a shallow repo.\n---\n Documentation/fetch-options.txt | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt\nindex 45583d8..78cd265 100644\n--- a/Documentation/fetch-options.txt\n+++ b/Documentation/fetch-options.txt\n@@ -8,10 +8,11 @@\n \toption old data in `.git/FETCH_HEAD` will be overwritten.\n \n --depth=<depth>::\n-\tDeepen or shorten the history of a 'shallow' repository created by\n-\t`git clone` with `--depth=<depth>` option (see linkgit:git-clone[1])\n-\tto the specified number of commits from the tip of each remote\n-\tbranch history. Tags for the deepened commits are not fetched.\n+\tLimit fetching to the specified number of commits from the tip of\n+\teach remote branch history. If fetching to a 'shallow' repository\n+\tcreated by `git clone` with `--depth=<depth>` option (see\n+\tlinkgit:git-clone[1]), deepen or shorten the history to the specified\n+\tnumber of commits. Tags for the deepened commits are not fetched.\n \n --unshallow::\n \tIf the source repository is complete, convert a shallow\n-- \n2.7.0.windows.1\n"},{"id":"275949","messageId":"569695E7.4020704@gmail.com","threadId":"41135","inReplyTo":"568F7EDD.9020003@gmail.com","subject":"Re: [PATCH] docs: say \"commits\" in the --depth option wording for git-clone","fromName":"Sebastian Schuberth","fromEmail":"sschuberth@gmail.com","sentAt":"2016-01-13T18:22:31Z","receivedAt":"2016-01-13T18:22:31Z","isPatch":true,"sender":{"key":"sschuberth@gmail.com","avatar":"https://avatars.githubusercontent.com/u/349154?v=4"},"body":"On 08.01.2016 10:18, Sebastian Schuberth wrote:\n\n> It is not wrong to talk about \"revisions\" here, but in this context\n> revisions are always commits, and that is how we already name it in the\n> git-fetch docs. So align the docs by always referring to \"commits\".\n\nSorry for the missing sign-off, feel free to amend that in pu:\n\nSigned-off-by: Sebastian Schuberth <sschuberth@gmail.com>\n\n-- \nSebastian Schuberth\n"},{"id":"275951","messageId":"56969647.7020005@gmail.com","threadId":"41135","inReplyTo":"568F8244.2030309@gmail.com","subject":"Re: [PATCH] docs: clarify that --depth for git-fetch works with newly initialized repos","fromName":"Sebastian Schuberth","fromEmail":"sschuberth@gmail.com","sentAt":"2016-01-13T18:24:07Z","receivedAt":"2016-01-13T18:24:07Z","isPatch":true,"sender":{"key":"sschuberth@gmail.com","avatar":"https://avatars.githubusercontent.com/u/349154?v=4"},"body":"On 08.01.2016 10:32, Sebastian Schuberth wrote:\n\n> The original wording sounded as if --depth could only be used to deepen or\n> shorten the history of existing repos. However, that is not the case. In a\n> workflow like\n>\n>      $ git init\n>      $ git remote add origin https://github.com/git/git.git\n>      $ git fetch --depth=1\n>\n> The newly initialized repo is properly created as a shallow repo.\n\nSorry for the missing sign-off, feel free to amend that in pu:\n\nSigned-off-by: Sebastian Schuberth <sschuberth@gmail.com>\n\n-- \nSebastian Schuberth\n"}]}