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

Re: teach git diff -v/--invert-match?

From
Jeff King <peff@peff.net>
Date
Aug 22, 2008, 21:42 UTC
Message-ID
<20080822214208.GA4498@coredump.intra.peff.net>
In-Reply-To
<48AF2FBB.2080401@visi.com>
On Fri, Aug 22, 2008 at 04:29:31PM -0500, Brian Ericson wrote:
Show 7 quoted lines
> I was just working on a reply to my own email as I realized it was
> only  dumb-luck that converted 1200 noisy changes into a couple of
> dozen.  "-S" matches only  the string itself, not the line the string
> resides on.  So, -Sxyz will match if  "xyz" itself was added or
> deleted in the diff (if "xyz" is on a line that's changed but  did not
> itself change, it won't match).  Funny that I actually knew this -- I
> use it to look for System.out.println additions among other things.

Yes (though I couldn't have told you that without experimenting -- I always assumed it checked whole lines).

> Interestingly, if I wanted to know if an import changed (on top of
> knowing if imports were added or deleted), eg: -import foo; +import
> bar;

That is a bit harder, and AFAIK not possible with -S. You could always post process the log output. E.g.,:

  git log -p | perl -ne '
    BEGIN { $/ = "commit " }
    chomp; print if /^\+import /
  '
which lets you get quite fancy with the matching.
> The current behavior seems to work well to answer questions like "has
> somebody added a System.out.println",

The usual question (for me, anyway) is "when did X get introduced?" when looking for a token.

-Peff
Previous: Brian EricsonNext: Junio C Hamano
Message 4 of 7 in “teach git diff -v/--invert-match?”
  1. Brian EricsonAug 22, 2008
  2. Jeff KingAug 22, 2008
  3. Brian EricsonAug 22, 2008
  4. Jeff KingAug 22, 2008
  5. Junio C HamanoAug 22, 2008
  6. Paolo BonziniAug 25, 2008
  7. Jeff KingAug 27, 2008

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.