2

I work with a codebase that has a lot of duplication. It seems the files were copied and then slightly modified, say bumping version numbers in string output and creation time-stamps.

Is there a way to tell git diff to ignore lines (a) in which only a specific number or digit is replaced by another (e.g. version_5 and version_6) or (b) in which the difference is digits only?

I know that git diff is quite flexible and I've read this answer about ignoring comments, but I don't see how I find out anything about the difference between two lines (like, if it's only digits that are different).

Quirin F. Schroll
  • 1,302
  • 1
  • 11
  • 25

1 Answers1

4

There is no way to tell git diff to ignore numeric changes.

You could pre-filter the files with sed and then pass them to the regular diff command. For example, here we use sed to convert all numbers to _, and compare the current version of the file to the version in the parent commit:

diff -u \
  <(git show HEAD:path/to/file | sed 's/[0-9]/_/g') \
  <(git show HEAD^:path/to/file | sed 's/[0-9]/_/g')
larsks
  • 277,717
  • 41
  • 399
  • 399