ignoring changes matching a string in git diff

Try the following:

$ git diff > full_diff.txt
$ git diff -G "your pattern" > matching_diff.txt

You can then compare the two like so:

$ diff matching_diff.txt full_diff.txt

If all changes match the pattern, full_diff.txt and matching_diff.txt will be identical, and the last diff command will not return anything.

If there are changes that do not match the pattern, the last diff will highlight those.


You can combine all of the above steps and avoid having to create two extra files like so:

diff <(git diff -G "your pattern") <(git diff)  # works with other diff tools too

Leave a Comment