{"thread":{"id":"60154","subject":"confused git diff -G","startedAt":"2023-08-24T22:09:33Z","lastAt":"2023-08-25T17:22:22Z","messageCount":5,"participants":["Alexei Podtelezhnikov","Taylor Blau","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"481020","messageId":"CAJU=AjWatV6A5Vx-yqRfG=yeUWxMvKocc4nTsdq58WHjaYFEzw@mail.gmail.com","threadId":"60154","inReplyTo":null,"subject":"confused git diff -G","fromName":"Alexei Podtelezhnikov","fromEmail":"apodtele@gmail.com","sentAt":"2023-08-24T22:08:18Z","receivedAt":"2023-08-24T22:09:33Z","isPatch":false,"sender":{"key":"apodtele@gmail.com","avatar":null},"body":"I find this sections of the docs confusing:\n\ngit diff -G (https://git.kernel.org/pub/scm/git/git.git/tree/Documentation/diff-options.txt#n656)\n\n I do not follow why the example talks about `git log -G` and commits.\nI see that thai file is included in git-log .txt but I do not\nunderstand how to use git  diff -G.\n\nA.\n"},{"id":"481024","messageId":"ZOfgKQfqvef9FXZ6@nand.local","threadId":"60154","inReplyTo":"CAJU=AjWatV6A5Vx-yqRfG=yeUWxMvKocc4nTsdq58WHjaYFEzw@mail.gmail.com","subject":"Re: confused git diff -G","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2023-08-24T22:56:41Z","receivedAt":"2023-08-24T22:57:17Z","isPatch":false,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Thu, Aug 24, 2023 at 06:08:18PM -0400, Alexei Podtelezhnikov wrote:\n> I find this sections of the docs confusing:\n>\n> git diff -G (https://git.kernel.org/pub/scm/git/git.git/tree/Documentation/diff-options.txt#n656)\n>\n>  I do not follow why the example talks about `git log -G` and commits.\n> I see that thai file is included in git-log .txt but I do not\n> understand how to use git  diff -G.\n\nI agree that it can be somewhat confusing :-).\n\nThe linked section DIFFCORE-PICKAXE in gitdiffcore(7) may be helpful:\n\n    DIFFCORE-PICKAXE: FOR DETECTING ADDITION/DELETION OF SPECIFIED STRING\n           This transformation limits the set of filepairs to those that\n           change specified strings between the preimage and the\n           postimage in a certain way. -S<block of text> and -G<regular\n           expression> options are used to specify different ways these\n           strings are sought.\n\n           [...]\n\n           \"-G<regular expression>\" (mnemonic: grep) detects filepairs\n           whose textual diff has an added or a deleted line that\n           matches the given regular expression. This means that it will\n           detect in-file (or what rename-detection considers the same\n           file) moves, which is noise. The implementation runs diff\n           twice and greps, and this can be quite expensive. To speed\n           things up binary files without textconv filters will be\n           ignored.\n\nSo if I have a setup like:\n\n    $ git init repo\n    $ git -C repo commit --allow-empty -m base\n    $ for c in a b; do echo $c>repo/$c && git -C $repo add $c; done\n    $ git -C repo commit -m changes\n\nThen you can see `-G` has the effect of limiting the output of 'git\ndiff' to just those file(s) whose diff matches the regular expression\ngiven to `-G`, like so:\n\n    $ git -C repo diff --stat HEAD^\n     a | 1 +\n     b | 1 +\n     2 files changed, 2 insertions(+)\n    $ git -C repo diff --stat HEAD^ -G a\n     a | 1 +\n     1 file changed, 1 insertion(+)\n    $ git -C repo diff --stat HEAD^ -G b\n     b | 1 +\n     1 file changed, 1 insertion(+)\n\n(I'm using --stat here to keep the output brief, since the contents are\nonly important insomuch as files \"a\" and \"b\" match the regular\nexpressions \"a\" and \"b\", respectively).\n\nThanks,\nTaylor\n"},{"id":"481026","messageId":"CAJU=AjU6cggm+P3d_Ke4uyks79j7uYipbp0xPq7jJ+nCgNSUZg@mail.gmail.com","threadId":"60154","inReplyTo":"ZOfgKQfqvef9FXZ6@nand.local","subject":"Re: confused git diff -G","fromName":"Alexei Podtelezhnikov","fromEmail":"apodtele@gmail.com","sentAt":"2023-08-25T00:53:06Z","receivedAt":"2023-08-25T00:54:11Z","isPatch":false,"sender":{"key":"apodtele@gmail.com","avatar":null},"body":"On Thu, Aug 24, 2023 at 6:56 PM Taylor Blau <me@ttaylorr.com> wrote:\n>\n> On Thu, Aug 24, 2023 at 06:08:18PM -0400, Alexei Podtelezhnikov wrote:\n> > I find this sections of the docs confusing:\n> >\n> > git diff -G (https://git.kernel.org/pub/scm/git/git.git/tree/Documentation/diff-options.txt#n656)\n> >\n> >  I do not follow why the example talks about `git log -G` and commits.\n> > I see that thai file is included in git-log .txt but I do not\n> > understand how to use git  diff -G.\n>\n> I agree that it can be somewhat confusing :-).\n\n[skip to the practical example]\n\n> given to `-G`, like so:\n>\n>     $ git -C repo diff --stat HEAD^\n>      a | 1 +\n>      b | 1 +\n>      2 files changed, 2 insertions(+)\n>     $ git -C repo diff --stat HEAD^ -G a\n>      a | 1 +\n>      1 file changed, 1 insertion(+)\n>     $ git -C repo diff --stat HEAD^ -G b\n>      b | 1 +\n>      1 file changed, 1 insertion(+)\n\nDo you mean that-G is only useful to filter files and not the content\nof changes? That I can do without -G. Canyou give a better example?\n"},{"id":"481027","messageId":"CAJU=AjW24gHCv-K97z=9KZJ4eqOEPvOR_6egFWZtnrZ21c3n8w@mail.gmail.com","threadId":"60154","inReplyTo":"CAJU=AjU6cggm+P3d_Ke4uyks79j7uYipbp0xPq7jJ+nCgNSUZg@mail.gmail.com","subject":"Re: confused git diff -G","fromName":"Alexei Podtelezhnikov","fromEmail":"apodtele@gmail.com","sentAt":"2023-08-25T03:43:43Z","receivedAt":"2023-08-25T03:45:13Z","isPatch":false,"sender":{"key":"apodtele@gmail.com","avatar":null},"body":"> > given to `-G`, like so:\n> >\n> >     $ git -C repo diff --stat HEAD^\n> >      a | 1 +\n> >      b | 1 +\n> >      2 files changed, 2 insertions(+)\n> >     $ git -C repo diff --stat HEAD^ -G a\n> >      a | 1 +\n> >      1 file changed, 1 insertion(+)\n> >     $ git -C repo diff --stat HEAD^ -G b\n> >      b | 1 +\n> >      1 file changed, 1 insertion(+)\n\nNever mind my last blurp, thank you for the explanation.\n\nThis is how I thought it works but the docs *^^$@%&$ for either\ngit-log or git-diff: the example from diff but the text is from log.\nIt could not be more confusing than this, not just might. If you want\nto share the text, it should be generic.\n"},{"id":"481031","messageId":"xmqqfs479gwx.fsf@gitster.g","threadId":"60154","inReplyTo":"ZOfgKQfqvef9FXZ6@nand.local","subject":"Re: confused git diff -G","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-08-25T17:21:34Z","receivedAt":"2023-08-25T17:22:22Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n> Then you can see `-G` has the effect of limiting the output of 'git\n> diff' to just those file(s) whose diff matches the regular expression\n> given to `-G`, like so:\n>\n>     $ git -C repo diff --stat HEAD^\n>      a | 1 +\n>      b | 1 +\n>      2 files changed, 2 insertions(+)\n>     $ git -C repo diff --stat HEAD^ -G a\n>      a | 1 +\n>      1 file changed, 1 insertion(+)\n>     $ git -C repo diff --stat HEAD^ -G b\n>      b | 1 +\n>      1 file changed, 1 insertion(+)\n\nAll true.\n\nAs this feature is primarily designed to help \"git log\" to choose\nwhich commit to show and which commit to omit in its output, readers\nwould not appreciate the usefulness of the feature, when shown in\nthe context of \"git diff\".\n\nEven more puzzling is how the \"--full-diff\" option works in\ncombination with \"-G\" or \"-S\" (or --diff-filter=... for that\nmatter)..\n\nThey make perfect sense as ingredients of a mechanism to choose\nwhich commit to show in the context of \"git log\", but their value is\nnot immediately apparent in the context of \"git diff\".  Continuing\nwith your example [*1*], comparing what these two do would be\nilluminating:\n\n    $ git -C repo diff --full-diff --stat -G b HEAD^\n    $ git -C repo diff --full-diff --stat -G c HEAD^\n\nThe former should show changes to both a and b, and the latter\nshould show nothing.\n\nWhile the way how each of these behaves makes perfect sense at the\nlogical level, it would be very puzzling why anybody may even want\nto use such a feature in the first place.  Until you realize that\ncomparing the previous commit and the current state (which happens\nto be identical to the current commit) is more or less a degenerated\nform of running \"log -n <n> HEAD\" with <n> set to 1, that is.\n\n\n[Footnote]\n\n*1* By the way, as an experienced mentor, avoid giving a command\n    line example that has dashed options after revs and paths.  It\n    may happen to do what you intended, but is confusing to readers.\n"}]}