git diff - show me line ending changes?

Stonky picture Stonky · Oct 13, 2010 · Viewed 47.7k times · Source

My editor is changing the line endings of my source files. When I do git diff, I see the same line twice -- once with - and once with + -- with no visible difference.

How do I get git diff to show me what this change actually was?

Answer

Paul Whittaker picture Paul Whittaker · Jul 16, 2012

First, make sure you're using the coloured output (e.g. with git diff --color) and that you've enabled whitespace highlighting with (e.g.)

git config color.diff.whitespace "red reverse"

This might not work in all cases, however, as git doesn't appear to highlight trailing whitespace for removed lines. To see whitespace that you've deleted, simply use

git diff -R

to put the whitespace on the 'added' side of the comparison, where it does get highlighted.

For more detail, see the answers at this SO question.