Re: git diff -G: Regex pattern to exclude a word
- From
Chris Torek <chris.torek@gmail.com>
- Date
- Jan 29, 2025, 11:01 UTC
- Message-ID
- <CAPx1Gvf+80Yty1R3O766fwYiRUysQ3Ss1XbFq7hmrfcUcawBAA@mail.gmail.com>
- In-Reply-To
- <CA+U2-7GiHq9qhiyLPLgzOd1JK072gzkmZ+4vQ11V0QpKgPif=Q@mail.gmail.com>
On Tue, Jan 28, 2025 at 10:05 PM Raghavendra N <nraghavendra89@gmail.com> wrote:
> I'm trying to understand how the -G option in git diff works. > Specifically I'm trying to test a Regex which excludes a word from the > git diff.
"Inverting" a regular expression is technically always possible, but is difficult to get right, and I think you made a slight error in your attempt. See also https://www.vidarholen.net/contents/blog/?p=36 (which has a link to a Haskell program to generate an inverted regex automatically).
With `git grep` you can specify perl-style regular expressions, which allow negative lookahead, but `git diff -G` does not support that. See https://stackoverflow.com/questions/39789921/what-flavor-of-regex-does-git-use for details.
I think it would be nice to add some of `git grep`'s options to `git diff` here, but I leave that as an exercise. :-)
Chris