Is there a way to remove version number change noise from a Git diff like this one? Specifically if a line only contains changes from one number to another can I set up Git diff to ignore it?
-
1Do those files even belong in source control? – Code-Apprentice Mar 06 '18 at 16:49
-
Perhaps the -g option helps? – Christoph Mar 06 '18 at 16:54
-
@Code-Apprentice Git is used to track changes to the strings inside an third party app. I don't think your question is relevant to mine. In the interest of keeping this comment on topic: Is there a way to automatically unstage these changes? – Steve Moser Mar 06 '18 at 16:55
-
You can specify a custom diff command for git, which could then filter such things out, but the versions that are mentioned in your example are all over the place and may be hard to write filters for. – Adam Katz Apr 17 '18 at 18:25
-
Smudge and clean filters? https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes – Mort Apr 18 '18 at 02:17
1 Answers
I think this can be achieved using git-diff --word-diff-regex=[^0-9]
(see [^0-9] in action). For a more complex pattern you'll need a more complex regex but, except recursion, everything is possible with regex.
From Git - git-diff --word-diff-regex documentation
--word-diff-regex=
Use < regex > to decide what a word is, instead of considering runs of non-whitespace to be a word. Also implies
--word-diff
unless it was already enabled.Every non-overlapping match of the < regex > is considered a word. Anything between these matches is considered whitespace and ignored(!) for the purposes of finding differences. You may want to append
|[^[:space:]]
to your regular expression to make sure that it matches all non-whitespace characters. A match that contains a newline is silently truncated(!) at the newline.For example,
--word-diff-regex=.
will treat each character as a word and, correspondingly, show differences character by character.The regex can also be set via a diff driver or configuration option, see gitattributes[5] or git-config[1]. Giving it explicitly overrides any diff driver or configuration setting. Diff drivers override configuration settings.
See also

- 1,984
- 1
- 11
- 24
-
1Thanks. This pointed me in the right direction. I updated the regex to ignore `.` as well and added -U0 from this answer: https://stackoverflow.com/questions/33159394/ignore-all-whitespace-changes-with-git-diff-between-commits to remove context. And I ended up with this: `git diff -w -U0 --word-diff-regex=[^0-9\.]` – Steve Moser Apr 18 '18 at 14:30
-
-
1
-
@SteveMoser that timer just expired. Anyway, how do I now suppress the chunks that have no changes left? I still get them in my output albeit without the change highlighted. I have a script updating 100 files and as long as that only changes numbers, I'm fine but I don't want to scroll through hundreds of empty chunks. – Giszmo Jan 10 '20 at 02:54