Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make Git diff ignore version number changes?

Tags:

git

git-diff

diff

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?

like image 587
Steve Moser Avatar asked Mar 06 '18 16:03

Steve Moser


People also ask

What does ++ mean in git diff?

When viewing a combined diff, if the two files you're comparing have a line that's different from what they were merged into, you will see the ++ to represent: one line that was added does not appear in either file1 or file2.

What do the numbers in git diff mean?

- means "old", as we usually invoke it as diff -u old new . +1,4 means that this piece of the second file starts at line 1 and shows a total of 4 lines. Therefore it shows lines 1 to 4. + means "new". We only have 4 lines instead of 6 because 2 lines were removed!

How do I terminate git diff?

To exit this you can use: :q for exit; :h for help; Note: if you don't want to read the output in pager you can use an ENV variable GIT_PAGER to cat or you need to set core.

What does M mean in git diff?

^M represents carriage return. This diff means something removed a Unicode BOM from the beginning of the line and added a CR at the end.


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

  • Git - git-diff --word-diff
like image 117
raul.vila Avatar answered Oct 13 '22 16:10

raul.vila