How to grep the git diff? How to grep the git diff? git git

How to grep the git diff?


Not sure but isn't git diff -G <regex> flag OK?

-G < regex>

Look for differences whose added or removed line matches the given <regex>.


Have you tried git diff -S<string> or git diff -G".*string.*"? Note that they are not equivalent, see the documentation about pickaxe for what -S does.


Another possibility would be to view the whole diff and search the output using the normal less commands (type / and then the pattern).

When you have less configured to show some lines before the match using --jump-target=N, this is pretty useful. Try it like this:

PAGER="/usr/bin/less --jump-target=10" git diff

This means that the match should be shown on line 10 (shows 9 lines of context above), which may be enough to also see the file name.

You can also use e.g. --jump-target=.5 to make it position the match in the middle of the screen.