From: Junio C Hamano <gitster@pobox.com>
To: Taylor Blau <me@ttaylorr.com>
Cc: Alexei Podtelezhnikov <apodtele@gmail.com>, git@vger.kernel.org
Subject: Re: confused git diff -G
Date: Fri, 25 Aug 2023 10:21:34 -0700 [thread overview]
Message-ID: <xmqqfs479gwx.fsf@gitster.g> (raw)
In-Reply-To: <ZOfgKQfqvef9FXZ6@nand.local> (Taylor Blau's message of "Thu, 24 Aug 2023 18:56:41 -0400")
Taylor Blau <me@ttaylorr.com> writes:
> Then you can see `-G` has the effect of limiting the output of 'git
> diff' to just those file(s) whose diff matches the regular expression
> given to `-G`, like so:
>
> $ git -C repo diff --stat HEAD^
> a | 1 +
> b | 1 +
> 2 files changed, 2 insertions(+)
> $ git -C repo diff --stat HEAD^ -G a
> a | 1 +
> 1 file changed, 1 insertion(+)
> $ git -C repo diff --stat HEAD^ -G b
> b | 1 +
> 1 file changed, 1 insertion(+)
All true.
As this feature is primarily designed to help "git log" to choose
which commit to show and which commit to omit in its output, readers
would not appreciate the usefulness of the feature, when shown in
the context of "git diff".
Even more puzzling is how the "--full-diff" option works in
combination with "-G" or "-S" (or --diff-filter=... for that
matter)..
They make perfect sense as ingredients of a mechanism to choose
which commit to show in the context of "git log", but their value is
not immediately apparent in the context of "git diff". Continuing
with your example [*1*], comparing what these two do would be
illuminating:
$ git -C repo diff --full-diff --stat -G b HEAD^
$ git -C repo diff --full-diff --stat -G c HEAD^
The former should show changes to both a and b, and the latter
should show nothing.
While the way how each of these behaves makes perfect sense at the
logical level, it would be very puzzling why anybody may even want
to use such a feature in the first place. Until you realize that
comparing the previous commit and the current state (which happens
to be identical to the current commit) is more or less a degenerated
form of running "log -n <n> HEAD" with <n> set to 1, that is.
[Footnote]
*1* By the way, as an experienced mentor, avoid giving a command
line example that has dashed options after revs and paths. It
may happen to do what you intended, but is confusing to readers.
prev parent reply other threads:[~2023-08-25 17:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-24 22:08 confused git diff -G Alexei Podtelezhnikov
2023-08-24 22:56 ` Taylor Blau
2023-08-25 0:53 ` Alexei Podtelezhnikov
2023-08-25 3:43 ` Alexei Podtelezhnikov
2023-08-25 17:21 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqfs479gwx.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=apodtele@gmail.com \
--cc=git@vger.kernel.org \
--cc=me@ttaylorr.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).