git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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
Previous: Raghavendra N
Message 2 of 2 in “git diff -G: Regex pattern to exclude a word”
  1. Raghavendra NJan 29, 2025
  2. Chris TorekJan 29, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.