{"thread":{"id":"28059","subject":"About git-diff","startedAt":"2011-08-10T01:52:57Z","lastAt":"2011-08-11T11:17:16Z","messageCount":5,"participants":["Luiz Ramos","Andreas Schwab","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"173227","messageId":"1312941177.17928.YahooMailClassic@web121810.mail.ne1.yahoo.com","threadId":"28059","inReplyTo":null,"subject":"About git-diff","fromName":"Luiz Ramos","fromEmail":"luizzramos@yahoo.com.br","sentAt":"2011-08-10T01:52:57Z","receivedAt":"2011-08-10T01:52:57Z","isPatch":false,"sender":{"key":"luizzramos@yahoo.com.br","avatar":null},"body":"Hello,\n\njust a doubt, but it can also be a bug.\n\nSuppose there is a project stored in git, and it has two branches. In the branch b1, there is a single file, file_1. In the branch b2, there is a single file file_2.\n\nSuppose also I am using branch b1 above (that is, \"git checkout b1\" was previously run), but the file file_2 was left in the working directory along with file_1.\n\nIf I run:\n\n$ git diff --cached b2 ./\n\nThe results will point that the file file_1 is added, as it is in the index and not in the tree b2. It will also point that file file_2 is removed, as it is listed in the tree b2, but not in the index. No doubts here.\n\nIf I run:\n\n$ git diff b2 ./\n\nthat is, the \"non-cached\" version, it will show the same results. This is confusing IMHO, because the git-diff manual suggests that invocation should render the difference between the named tree contents and the working directory. In the working directory, only to recall, file_1 and file_2 are both present and with good versions. In my understanding, the command should report that file_1 is in excess in the working directory, relative to b2, and report nothing about file_2, as it is in the same version as the sample in the tree b2.\n\nThis doesn't seem to be the same thing git-diff-index manual states, however. The manual gets more deep into the details, and it's not so easy to understand it unless one knows a lot of the inner commands, which does not apply to me. In my basic reading, it seems that behind the scenes, git-diff-index is what is run in this case, and the fact that file_2 is not in the tree associated to b1 is a relevant thing in this case. So, the index seem to matter, and if I try to do it, a previous \"git update-index\" should be done.\n\nI may be wrong, but as a user, I'd like to have the non-cached command version comparing tree and working directory, as the manual of git-diff suggests, eventually helped by the index, but not limited to it. Because if I'd like to compare with index, I would try it using --cached instead.\n\nPlease accept my apologies if there is some newbie mistake here.\n\nThanks,\n\nLuiz Ramos\nSão Paulo - Brazil\n"},{"id":"173246","messageId":"m2hb5pb3pe.fsf@igel.home","threadId":"28059","inReplyTo":"1312941177.17928.YahooMailClassic@web121810.mail.ne1.yahoo.com","subject":"Re: About git-diff","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2011-08-10T17:01:49Z","receivedAt":"2011-08-10T17:01:49Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"Luiz Ramos <luizzramos@yahoo.com.br> writes:\n\n> If I run:\n>\n> $ git diff b2 ./\n>\n> that is, the \"non-cached\" version, it will show the same results. This is\n> confusing IMHO, because the git-diff manual suggests that invocation\n> should render the difference between the named tree contents and the\n> working directory. In the working directory, only to recall, file_1 and\n> file_2 are both present and with good versions. In my understanding, the\n> command should report that file_1 is in excess in the working directory,\n> relative to b2, and report nothing about file_2, as it is in the same\n> version as the sample in the tree b2.\n\nSince file_2 is not tracked in the current branch, its existence in the\ndirectory is ignored.\n\n> This doesn't seem to be the same thing git-diff-index manual states,\n> however. The manual gets more deep into the details, and it's not so easy\n> to understand it unless one knows a lot of the inner commands, which does\n> not apply to me. In my basic reading, it seems that behind the scenes,\n> git-diff-index is what is run in this case, and the fact that file_2 is\n> not in the tree associated to b1 is a relevant thing in this case. So, the\n> index seem to matter, and if I try to do it, a previous \"git update-index\"\n> should be done.\n\nIt's not the index, but the current tree that matters:\n\n           show me the differences between HEAD and the currently checked out\n           tree - index contents _and_ files that aren't up-to-date\n\nNote that it talks about \"files that aren't up-to-date\".  Thus untracked\nfiles are not considered.\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5\n\"And now for something completely different.\"\n"},{"id":"173253","messageId":"1313024025.97405.YahooMailClassic@web121818.mail.ne1.yahoo.com","threadId":"28059","inReplyTo":"m2hb5pb3pe.fsf@igel.home","subject":"Re: About git-diff","fromName":"Luiz Ramos","fromEmail":"luizzramos@yahoo.com.br","sentAt":"2011-08-11T00:53:45Z","receivedAt":"2011-08-11T00:53:45Z","isPatch":false,"sender":{"key":"luizzramos@yahoo.com.br","avatar":null},"body":"\n--- Em qua, 10/8/11, Andreas Schwab <schwab@linux-m68k.org> escreveu:\n\n> De: Andreas Schwab <schwab@linux-m68k.org>\n> Assunto: Re: About git-diff\n> Para: \"Luiz Ramos\" <luizzramos@yahoo.com.br>\n> Cc: git@vger.kernel.org\n> Data: Quarta-feira, 10 de Agosto de 2011, 14:01\n> Luiz Ramos <luizzramos@yahoo.com.br>\n> writes:\n> \n> > If I run:\n> >\n> > $ git diff b2 ./\n> >\n> > that is, the \"non-cached\" version, it will show the\n> same results. This is\n> > confusing IMHO, because the git-diff manual suggests\n> that invocation\n> > should render the difference between the named tree\n> contents and the\n> > working directory. In the working directory, only to\n> recall, file_1 and\n> > file_2 are both present and with good versions. In my\n> understanding, the\n> > command should report that file_1 is in excess in the\n> working directory,\n> > relative to b2, and report nothing about file_2, as it\n> is in the same\n> > version as the sample in the tree b2.\n> \n> Since file_2 is not tracked in the current branch, its\n> existence in the\n> directory is ignored.\n> \n> > This doesn't seem to be the same thing git-diff-index\n> manual states,\n> > however. The manual gets more deep into the details,\n> and it's not so easy\n> > to understand it unless one knows a lot of the inner\n> commands, which does\n> > not apply to me. In my basic reading, it seems that\n> behind the scenes,\n> > git-diff-index is what is run in this case, and the\n> fact that file_2 is\n> > not in the tree associated to b1 is a relevant thing\n> in this case. So, the\n> > index seem to matter, and if I try to do it, a\n> previous \"git update-index\"\n> > should be done.\n> \n> It's not the index, but the current tree that matters:\n> \n>            show me the\n> differences between HEAD and the currently checked out\n>            tree - index\n> contents _and_ files that aren't up-to-date\n> \n> Note that it talks about \"files that aren't\n> up-to-date\".  Thus untracked\n> files are not considered.\n> \n\nOk, understood.\n\nGiven this, I'd suggest to change the inline documentation of git-diff (git help diff). In the version of my machine (1.7.4.4), it's like that:\n\n(snip)\n...\n       git diff [--options] <commit> [--] [<path>...]\n           This form is to view the changes you have in your working tree\n           relative to the named <commit>. You can use HEAD to compare it with\n           the latest commit, or a branch name to compare with the tip of a\n           different branch.\n...\n(snip)\n\nA unadvised reader could understand that the comparison is between <commit> and the working directory, as if <commit> was the current branch, plainly stated. In fact, there is no mention to the current branch, or to the files being tracked or not, except for the option of mentioning HEAD as the <commit> to be taken into account.\n\nIf you'd accept a small contribution of yours truly, here's amy suggestion for this text:\n\n...\n       git diff [--options] <commit> [--] [<path>...]\n           This form is to view the changes you have in your working tree\n           relative to the named <commit>. You can use HEAD to compare it with\n           the latest commit, or a branch name to compare with the tip of a\n           different branch. Note, however, that files untracked in the \n           current branch are handled as if they are missing in the working\n           directory. Check out git-diff-index documentation for further\n           information.\n...\n\nIt's not in the patch format, but if you'd like the suggestion, there is no problem in re-sending it as a formatted patch.\n\nThanks,\n\nLuiz\n\n\n> Andreas.\n> \n> -- \n> Andreas Schwab, schwab@linux-m68k.org\n> GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3\n> 44D5 214B 8276 4ED5\n> \"And now for something completely different.\"\n> \n"},{"id":"173254","messageId":"7vr54sr1qi.fsf@alter.siamese.dyndns.org","threadId":"28059","inReplyTo":"1313024025.97405.YahooMailClassic@web121818.mail.ne1.yahoo.com","subject":"Re: About git-diff","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-08-11T04:49:57Z","receivedAt":"2011-08-11T04:49:57Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Luiz Ramos <luizzramos@yahoo.com.br> writes:\n\n> Given this, I'd suggest to change the inline documentation of git-diff (git help diff). In the version of my machine (1.7.4.4), it's like that:\n>\n> (snip)\n> ...\n>        git diff [--options] <commit> [--] [<path>...]\n>            This form is to view the changes you have in your working tree\n>            relative to the named <commit>. You can use HEAD to compare it with\n>            the latest commit, or a branch name to compare with the tip of a\n>            different branch.\n> ...\n\nStrictly speaking, \"the changes you have in your working tree\" may be what\nis confusing. Your working tree does _not_ have \"changes\"; it only has\n\"contents\". Changes are perceived only if you compare it with something\nelse, as their _difference_.\n\nThis operation compares \"the contents of tracked files in your working\ntree\" with \"the contents recorded in the named <commit>\"---the result of\nthis comparison comparison matches what humans perceive as \"changes\".\n\nSo perhaps updating the first sentence with:\n\n\tCompare the contents of tracked files in your working tree with\n\twhat is recorded in the named <commit>.\n\nwould be all that is necessary. I didn't bother to look but I suspect we\nhave a simlar description for \"git diff [--options] [--] [<path>...]\"\nform, and it should be updated in a similar way (the only difference is\nthat it compares \"with what is recorded in the index\").\n"},{"id":"173282","messageId":"1313061436.22648.YahooMailClassic@web121810.mail.ne1.yahoo.com","threadId":"28059","inReplyTo":"7vr54sr1qi.fsf@alter.siamese.dyndns.org","subject":"Re: About git-diff","fromName":"Luiz Ramos","fromEmail":"luizzramos@yahoo.com.br","sentAt":"2011-08-11T11:17:16Z","receivedAt":"2011-08-11T11:17:16Z","isPatch":false,"sender":{"key":"luizzramos@yahoo.com.br","avatar":null},"body":"\n\n--- Em qui, 11/8/11, Junio C Hamano <gitster@pobox.com> escreveu:\n\n> Luiz Ramos <luizzramos@yahoo.com.br>\n> writes:\n> \n> > Given this, I'd suggest to change the inline\n> documentation of git-diff (git help diff). In the version of\n> my machine (1.7.4.4), it's like that:\n> >\n> > (snip)\n> > ...\n> >        git diff [--options]\n> <commit> [--] [<path>...]\n> >            This form is\n> to view the changes you have in your working tree\n> >            relative to\n> the named <commit>. You can use HEAD to compare it\n> with\n> >            the latest\n> commit, or a branch name to compare with the tip of a\n> >            different\n> branch.\n> > ...\n> \n> Strictly speaking, \"the changes you have in your working\n> tree\" may be what\n> is confusing. Your working tree does _not_ have \"changes\";\n> it only has\n> \"contents\". Changes are perceived only if you compare it\n> with something\n> else, as their _difference_.\n> \n> This operation compares \"the contents of tracked files in\n> your working\n> tree\" with \"the contents recorded in the named\n> <commit>\"---the result of\n> this comparison comparison matches what humans perceive as\n> \"changes\".\n> \n> So perhaps updating the first sentence with:\n> \n>     Compare the contents of tracked files in\n> your working tree with\n>     what is recorded in the named\n> <commit>.\n> \n\nYes, agreed. This sentence seems to embed the right information in a more concise manner.\n\n> would be all that is necessary. I didn't bother to look but\n> I suspect we\n> have a simlar description for \"git diff [--options] [--]\n> [<path>...]\"\n> form, and it should be updated in a similar way (the only\n> difference is\n> that it compares \"with what is recorded in the index\").\n> \n\nIn my version (1.7.4.4):\n\n(snip)\n...\n       git diff [--options] [--] [<path>...]\n           This form is to view the changes you made relative to the index (staging area for the next commit). In other words, the differences are what you could tell git to further add to\n           the index but you still haven't. You can stage these changes by using git-add(1).\n...\n(snip)\n\nAnd yes, if an untracked new file is in the working directory, it is not reported. Again, the words \"changes\" and \"differences\" seem to be confusing in this case as new files may be seen as \"changes\" or \"differences\" for an operator not used to git.\n\nLuiz\n"}]}