{"thread":{"id":"46724","subject":"git diff <commit> doesn't quite work as documented?","startedAt":"2017-09-07T16:32:38Z","lastAt":"2017-09-09T11:39:09Z","messageCount":4,"participants":["Olaf Klischat","Junio C Hamano","Michael J Gruber","Yubin Ruan"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"327719","messageId":"0696f94d-28c2-1f4b-03ee-16553d97f318@gmail.com","threadId":"46724","inReplyTo":null,"subject":"git diff <commit> doesn't quite work as documented?","fromName":"Olaf Klischat","fromEmail":"olaf.klischat@gmail.com","sentAt":"2017-09-07T16:31:58Z","receivedAt":"2017-09-07T16:32:38Z","isPatch":false,"sender":{"key":"olaf.klischat@gmail.com","avatar":"https://gravatar.com/avatar/adbf3715021e1ded8e164c01a7a95f89eb23978e2248a60a5d43489f65151279?d=mp&s=160"},"body":"oklischat@oklischat:/tmp$ mkdir gittest\noklischat@oklischat:/tmp$ cd gittest/\noklischat@oklischat:/tmp/gittest$ git init\nInitialized empty Git repository in /private/tmp/gittest/.git/\noklischat@oklischat:/tmp/gittest$ echo foo > foo.txt\noklischat@oklischat:/tmp/gittest$ git add foo.txt\noklischat@oklischat:/tmp/gittest$ git commit -m foo\n[master (root-commit) 54d55f2] foo\n 1 file changed, 1 insertion(+)\n create mode 100644 foo.txt\noklischat@oklischat:/tmp/gittest$ echo bar > bar.txt\noklischat@oklischat:/tmp/gittest$ git add bar.txt\noklischat@oklischat:/tmp/gittest$ git commit -m bar\n[master 83b2e74] bar\n 1 file changed, 1 insertion(+)\n create mode 100644 bar.txt\noklischat@oklischat:/tmp/gittest$ git tag bar-added\noklischat@oklischat:/tmp/gittest$ git rm bar.txt\nrm 'bar.txt'\noklischat@oklischat:/tmp/gittest$ git commit -m 'rm bar'\n[master 3ca4ff9] rm bar\n 1 file changed, 1 deletion(-)\n delete mode 100644 bar.txt\noklischat@oklischat:/tmp/gittest$\noklischat@oklischat:/tmp/gittest$ git checkout bar-added -- bar.txt\noklischat@oklischat:/tmp/gittest$ git reset HEAD\noklischat@oklischat:/tmp/gittest$ git status\nOn branch master\nUntracked files:\n  (use \"git add <file>...\" to include in what will be committed)\n\n\tbar.txt\n\nnothing added to commit but untracked files present (use \"git add\" to track)\noklischat@oklischat:/tmp/gittest$ git diff bar-added   # would expect this to show no differences\ndiff --git a/bar.txt b/bar.txt\ndeleted file mode 100644\nindex 5716ca5..0000000\n--- a/bar.txt\n+++ /dev/null\n@@ -1 +0,0 @@\n-bar\noklischat@oklischat:/tmp/gittest$ \noklischat@oklischat:/tmp/gittest$ git diff bar-added  -- bar.txt   # dito\ndiff --git a/bar.txt b/bar.txt\ndeleted file mode 100644\nindex 5716ca5..0000000\n--- a/bar.txt\n+++ /dev/null\n@@ -1 +0,0 @@\n-bar\noklischat@oklischat:/tmp/gittest$ \n\n\n`git diff --help' says:\n\ngit diff [--options] <commit> [--] [<path>...]\n           This form is to view the changes you have in your working tree relative to the named <commit>.\n\nIf that were entirely true, the last two commands shouldn't have shown\nany differences, right?\n\nOn closer inspection, it seems that what `git diff <commit>' really\ndoes is take only those paths in the working directory that are also\nin <commit> and compare the resulting tree against <commit>.\n\nWe should add some option to that git diff form to make it really do\nwhat the docs claim it does.\n\nOr am I missing something?\n"},{"id":"327739","messageId":"xmqqfuby0yll.fsf@gitster.mtv.corp.google.com","threadId":"46724","inReplyTo":"0696f94d-28c2-1f4b-03ee-16553d97f318@gmail.com","subject":"Re: git diff <commit> doesn't quite work as documented?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-09-08T01:26:46Z","receivedAt":"2017-09-08T01:26:56Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Olaf Klischat <olaf.klischat@gmail.com> writes:\n\n> `git diff --help' says:\n>\n> git diff [--options] <commit> [--] [<path>...]\n>            This form is to view the changes you have in your\n>            working tree relative to the named <commit>.\n\nThat help text is poorly phrased.  \n\nWhen \"git diff\" talks about files in your working tree, it always\nlooks them _through_ the index.  As far as the command is concerned,\na cruft left in your working tree that is not in the index does\n*not* exist.\n\nSo when your index does not have bar.txt, even if you have an\nuntracked bar.txt in your directory, i.e.\n\n> oklischat@oklischat:/tmp/gittest$ git status\n> On branch master\n> Untracked files:\n>   (use \"git add <file>...\" to include in what will be committed)\n>\n> \tbar.txt\n\nand you have a commit that _has_ that file, then the command thinks\n<commit> has the path, and your working tree does *not*.  IOW, this\nis...\n\n> oklischat@oklischat:/tmp/gittest$ git diff bar-added\n> diff --git a/bar.txt b/bar.txt\n> deleted file mode 100644\n\n... totally expected and intended output.\n\nHope the above explanation clarifies.  A documentation update might\nbe helpful to new users.\n\nThanks.\n"},{"id":"327770","messageId":"c08ed84a-6c65-4278-851b-439c63c501ea@grubix.eu","threadId":"46724","inReplyTo":"xmqqfuby0yll.fsf@gitster.mtv.corp.google.com","subject":"Re: git diff <commit> doesn't quite work as documented?","fromName":"Michael J Gruber","fromEmail":"git@grubix.eu","sentAt":"2017-09-08T12:58:38Z","receivedAt":"2017-09-08T12:58:55Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Junio C Hamano venit, vidit, dixit 08.09.2017 03:26:\n> Olaf Klischat <olaf.klischat@gmail.com> writes:\n> \n>> `git diff --help' says:\n>>\n>> git diff [--options] <commit> [--] [<path>...]\n>>            This form is to view the changes you have in your\n>>            working tree relative to the named <commit>.\n> \n> That help text is poorly phrased.  \n> \n> When \"git diff\" talks about files in your working tree, it always\n> looks them _through_ the index.  As far as the command is concerned,\n> a cruft left in your working tree that is not in the index does\n> *not* exist.\n> \n> So when your index does not have bar.txt, even if you have an\n> untracked bar.txt in your directory, i.e.\n> \n>> oklischat@oklischat:/tmp/gittest$ git status\n>> On branch master\n>> Untracked files:\n>>   (use \"git add <file>...\" to include in what will be committed)\n>>\n>> \tbar.txt\n> \n> and you have a commit that _has_ that file, then the command thinks\n> <commit> has the path, and your working tree does *not*.  IOW, this\n> is...\n> \n>> oklischat@oklischat:/tmp/gittest$ git diff bar-added\n>> diff --git a/bar.txt b/bar.txt\n>> deleted file mode 100644\n> \n> ... totally expected and intended output.\n> \n> Hope the above explanation clarifies.  A documentation update might\n> be helpful to new users.\n\nWell, there's a difference between \"working tree\" and  \"working dir\".\nThe wt is \"the tree of actual checked out files\" per our glossary. So\nmaybe the doc could point to the glossary (see the glossary for the\ndifference to the work dir).\n\nBut really, this type of misunderstandings comes up often: people try to\nunderstand the doc based on common language terms (which is okay, of\ncourse) and are unaware of the defined meanings of technical terms.\nExplaining them in every place where they are used simply does not scale.\n\nMaybe we should make more use of our glossary (extend it, enhance it,\npromote it) and somehow mark all technical terms as such when they are\nused (say, italics in HTML), or at least when the exact meaning is\nrelevant like in the case above, and possibly link to the glossary (-item).\n\nMichael\n"},{"id":"327817","messageId":"CAJYFCiMV62HXD8++9ThvWWV8VELG89hUf++90TTCrD8ARMk2JA@mail.gmail.com","threadId":"46724","inReplyTo":"0696f94d-28c2-1f4b-03ee-16553d97f318@gmail.com","subject":"Re: git diff <commit> doesn't quite work as documented?","fromName":"Yubin Ruan","fromEmail":"ablacktshirt@gmail.com","sentAt":"2017-09-09T11:39:02Z","receivedAt":"2017-09-09T11:39:09Z","isPatch":false,"sender":{"key":"ablacktshirt@gmail.com","avatar":null},"body":"2017-09-08 0:31 GMT+08:00 Olaf Klischat <olaf.klischat@gmail.com>:\n> oklischat@oklischat:/tmp$ mkdir gittest\n> oklischat@oklischat:/tmp$ cd gittest/\n> oklischat@oklischat:/tmp/gittest$ git init\n> Initialized empty Git repository in /private/tmp/gittest/.git/\n> oklischat@oklischat:/tmp/gittest$ echo foo > foo.txt\n> oklischat@oklischat:/tmp/gittest$ git add foo.txt\n> oklischat@oklischat:/tmp/gittest$ git commit -m foo\n> [master (root-commit) 54d55f2] foo\n>  1 file changed, 1 insertion(+)\n>  create mode 100644 foo.txt\n> oklischat@oklischat:/tmp/gittest$ echo bar > bar.txt\n> oklischat@oklischat:/tmp/gittest$ git add bar.txt\n> oklischat@oklischat:/tmp/gittest$ git commit -m bar\n> [master 83b2e74] bar\n>  1 file changed, 1 insertion(+)\n>  create mode 100644 bar.txt\n> oklischat@oklischat:/tmp/gittest$ git tag bar-added\n> oklischat@oklischat:/tmp/gittest$ git rm bar.txt\n> rm 'bar.txt'\n> oklischat@oklischat:/tmp/gittest$ git commit -m 'rm bar'\n> [master 3ca4ff9] rm bar\n>  1 file changed, 1 deletion(-)\n>  delete mode 100644 bar.txt\n> oklischat@oklischat:/tmp/gittest$\n> oklischat@oklischat:/tmp/gittest$ git checkout bar-added -- bar.txt\n> oklischat@oklischat:/tmp/gittest$ git reset HEAD\n> oklischat@oklischat:/tmp/gittest$ git status\n> On branch master\n> Untracked files:\n>   (use \"git add <file>...\" to include in what will be committed)\n>\n>         bar.txt\n>\n> nothing added to commit but untracked files present (use \"git add\" to track)\n> oklischat@oklischat:/tmp/gittest$ git diff bar-added   # would expect this to show no differences\n> diff --git a/bar.txt b/bar.txt\n> deleted file mode 100644\n> index 5716ca5..0000000\n> --- a/bar.txt\n> +++ /dev/null\n> @@ -1 +0,0 @@\n> -bar\n> oklischat@oklischat:/tmp/gittest$\n> oklischat@oklischat:/tmp/gittest$ git diff bar-added  -- bar.txt   # dito\n> diff --git a/bar.txt b/bar.txt\n> deleted file mode 100644\n> index 5716ca5..0000000\n> --- a/bar.txt\n> +++ /dev/null\n> @@ -1 +0,0 @@\n> -bar\n\nMichael J Gruber is correct about the working-dir/working-tree things.\nA quick example: add a new file with\n\n    $ echo bzz > bzz.txt\n\nthen do \"git diff bar-added\".\n\nThe result is the same, because \"bzz.txt\" is not in the working-tree.\n\nYubin\n\n> oklischat@oklischat:/tmp/gittest$\n>\n>\n> `git diff --help' says:\n>\n> git diff [--options] <commit> [--] [<path>...]\n>            This form is to view the changes you have in your working tree relative to the named <commit>.\n>\n> If that were entirely true, the last two commands shouldn't have shown\n> any differences, right?\n>\n> On closer inspection, it seems that what `git diff <commit>' really\n> does is take only those paths in the working directory that are also\n> in <commit> and compare the resulting tree against <commit>.\n>\n> We should add some option to that git diff form to make it really do\n> what the docs claim it does.\n>\n> Or am I missing something?\n"}]}