2

I am producing a diff between two branches with a command like

git diff <branch-1> <branch-2>

Beside the actual code differences, there is a big noise because of many changes in the form

-       <version>42.2.0.12</version>
+       <version>42.3.0.10</version>

I would like to see a clean diff, where those differences are either excluded or non-highlighted.

I already checked two similar SO questions, which were of no help:

  1. How to make git diff ignore comments: leads to a non-working solution
  2. How do I make git diff ignore version number changes: is better, as it ignore the 'x.y.z', but leads to a messy git diff, where I cannot really see the lines that have changed because it reports the changes on each single word.

For instance, in the second case, I used

git diff -w --word-diff-regex='[^<version>(0-9\.)</version>]' <branch-1> <branch-2>

Now that the premise is set, the question is:

  • Is there a way to use git diff and just remove some unwanted differences such as <version>x.y.z</version> ?
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
psuzzi
  • 2,187
  • 1
  • 17
  • 21
  • 4
    Does this answer your question? [ignoring changes matching a string in git diff](https://stackoverflow.com/questions/15878622/ignoring-changes-matching-a-string-in-git-diff) – Tarek Dakhran Feb 21 '20 at 12:41
  • The suggested link is similar to the link 1. in my question: it uses the `-G` flag. Such flag does not work as requested in my question, by filtering out the commits not matching. If a solution with -G exists, I would like to know which RegExp can be used to match all the lines not containing x.y.z. And this, is the actual core of the question, which is specified in the title. Hence, the question is still is unanswered. – psuzzi Feb 23 '20 at 01:31
  • Closing this question as duplicate is poor review. In my question, the link 1. points to a SO solution using `git diff -G ` . I wrote that it leads to a non working solution. The link suggested by the reviewer has a solution `git diff -G "your pattern" > matching_diff.txt` which is the same as the one I pointed, but it writes to file - which makes it even worse, as you lose highlighting of the other diffs. – psuzzi Feb 23 '20 at 01:38
  • @TarekDakhran : no, it does not solve the issue. – psuzzi Feb 23 '20 at 01:45
  • Unless you can construct a way to use `git diff -G `, then no, git does not have a built-in way to do what you're asking. – Lasse V. Karlsen Jul 27 '20 at 09:25
  • Also note that this - `[^(0-9\.)]` - is a character set, it matches everything but the symbols `<`, `v`, `e`, `r`, `s`, and so on, it is not a patten that matches *text* other than `...`. it will match on one symbol, so as long as a line has at least one character that is *not* in that character set, it will match your regex. You will have to work harder with something like a negative lookahead to construct your regex, if at all possible. – Lasse V. Karlsen Jul 27 '20 at 09:27

0 Answers0