2

I am using:

git diff --ignore-space-at-eol -b -w --ignore-blank-lines --ignore-cr-at-eol COMMIT1 COMMIT2

to diff two commits removing white space but it still shows the following which is basically only a newline change:

- <div class="model-content" style="border: 2px solid #d5001e;border-radius: 8px;">
- <div class="model-header" style="border-bottom: 1px solid #d5001e;background: #d5001c;">
+ <div class="model-content"
+     style="border: 2px solid #d5001e;border-radius: 8px;">
+     <div class="model-header"
+         style="border-bottom: 1px solid #d5001e;background: #d5001c;">

Question: how to make git diff ignore these new lines?

1 Answer 1

3

Unfortunately, Git's main difference algorithm is line based. Lines are split before applying whitespace modifications (well, it's sort of mixed together really). The result is that any time an original single line becomes two lines, or vice versa, git diff itself will always see this as a change.1

Using Git's word-diff, you can have the algorithm's output post-processed in a way that ignores newlines. The result is rather funky in that if the actual change affects no words, you get a diff hunk header followed by a block showing no changes (!). This is no real help at all for your example, though.


1Technically, what's going on here is that Git is treating each input line as a single symbol. It then runs the chosen algorithm, usually Myers, over the symbols. Since the lines were split and became separate symbols, your particular example here has one symbol on the left side of the input that becomes two different symbols on the right side, for each of the two original <div ...> lines.

For much more about this, see what's currently pages 60–66 in the prototype of my stalled-out book.

Not the answer you're looking for? Browse other questions tagged or ask your own question.