git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Taylor Blau <me@ttaylorr.com>
To: Alexei Podtelezhnikov <apodtele@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: confused git diff -G
Date: Thu, 24 Aug 2023 18:56:41 -0400	[thread overview]
Message-ID: <ZOfgKQfqvef9FXZ6@nand.local> (raw)
In-Reply-To: <CAJU=AjWatV6A5Vx-yqRfG=yeUWxMvKocc4nTsdq58WHjaYFEzw@mail.gmail.com>

On Thu, Aug 24, 2023 at 06:08:18PM -0400, Alexei Podtelezhnikov wrote:
> I find this sections of the docs confusing:
>
> git diff -G (https://git.kernel.org/pub/scm/git/git.git/tree/Documentation/diff-options.txt#n656)
>
>  I do not follow why the example talks about `git log -G` and commits.
> I see that thai file is included in git-log .txt but I do not
> understand how to use git  diff -G.

I agree that it can be somewhat confusing :-).

The linked section DIFFCORE-PICKAXE in gitdiffcore(7) may be helpful:

    DIFFCORE-PICKAXE: FOR DETECTING ADDITION/DELETION OF SPECIFIED STRING
           This transformation limits the set of filepairs to those that
           change specified strings between the preimage and the
           postimage in a certain way. -S<block of text> and -G<regular
           expression> options are used to specify different ways these
           strings are sought.

           [...]

           "-G<regular expression>" (mnemonic: grep) detects filepairs
           whose textual diff has an added or a deleted line that
           matches the given regular expression. This means that it will
           detect in-file (or what rename-detection considers the same
           file) moves, which is noise. The implementation runs diff
           twice and greps, and this can be quite expensive. To speed
           things up binary files without textconv filters will be
           ignored.

So if I have a setup like:

    $ git init repo
    $ git -C repo commit --allow-empty -m base
    $ for c in a b; do echo $c>repo/$c && git -C $repo add $c; done
    $ git -C repo commit -m changes

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(+)

(I'm using --stat here to keep the output brief, since the contents are
only important insomuch as files "a" and "b" match the regular
expressions "a" and "b", respectively).

Thanks,
Taylor

  reply	other threads:[~2023-08-24 22:57 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 [this message]
2023-08-25  0:53   ` Alexei Podtelezhnikov
2023-08-25  3:43     ` Alexei Podtelezhnikov
2023-08-25 17:21   ` Junio C Hamano

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=ZOfgKQfqvef9FXZ6@nand.local \
    --to=me@ttaylorr.com \
    --cc=apodtele@gmail.com \
    --cc=git@vger.kernel.org \
    /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).