dshepherd dshepherd - 1 year ago 164
Git Question

ignoring changes matching a string in git diff

I've made a single simple change to a large number of files that are version controlled in git and I'd like to be able to check that no other changes are slipping into this large commit.

The changes are all of the form

- "main()",

where "main()" could be the name of any function. I want to generate a diff of all changes that are not of this form.

The -G and -S options to git diff are tantalisingly close--they find changes that DO match a string or regexp.

Is there a good way to do this?

Attempts so far

Another question describes how regexs can be negated, using this approach I think the command should be

git diff -G '^((?!OOMPH_CURRENT_FUNCTION).)*$'

but this just returns the error message

fatal: invalid log-grep regex: Invalid preceding regular expression

so I guess git doesn't support this regex feature.

I also noticed that the standard unix diff has the -I option to "ignore changes whose lines all match RE". But I can't find the correct way to replace git's own diff with the unix diff tool.

Answer Source

Since you say you can find the changes that DO match your pattern, I suggest the following:

  • git diff > full.txt
  • git diff -G your pattern > match.txt
  • diff full.txt match.txt with your favorite diff program (e.g. vimdiff)

If you only have changes that match the pattern, full.txt and match.txt should be identical. Otherwise, the last diff should highlight any non-matching changes.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download