Git diff - show lines end with changes?

My editor changes the line endings of my source files. When I do git diff , I see the same line twice - once with - and once with + - without visible differences.

How do I get git diff to show me what it really was?

+54
git git-diff line-endings
Oct 13 '10 at 3:52
source share
5 answers

First, make sure that you are using a color output (e.g. with git diff --color ) and that you have activated the highlighting with (e.g..)

 git config color.diff.whitespace "red reverse" 

This may not work in all cases, however, since git does not highlight extra spaces for deleted lines. To view the spaces you have removed, simply use

 git diff -R 

to put a space on the "added" side of the comparison, where it becomes highlighted.

See the answers to this SO question for more details.

+48
Jul 16 2018-12-17T00:
source share

You can see the difference at the end of the line with the following command.

 git diff | cat -v 

Then “^ M” is printed to end CRLF (DOS), nothing to end LF (Unix).

Git diff seems to be doing the right thing by printing CR and LF characters to end CRLF. But since CR is consumed by the console, we cannot see it. Using cat -v, we can make it visible.

+15
Sep 15 '16 at 2:51 on
source share

One way to see the changing spaces is to make a "word difference" character by character with

 git diff --color --word-diff-regex=. 

This underlines all spaces in all lines. Deleted spaces are wrapped in [- and -] and spaces are added in {+ and +} .

Alternatively as suggested by Alex

 git diff --color --ws-error-highlight=new,old 

highlights all whitespace changes at the ends of lines.

+9
Apr 13 '16 at 16:57
source share
 git diff --ws-error-highlight=new,old 

Highlights spaces that differ in changed lines.

+6
Apr 10 '16 at 23:23
source share

A graphical comparison tool will show you the changes better - try git difftool .

Use meld and set preferences to display spaces. (Change → Settings → Show spaces.)

Other graphical tools probably have similar options - @Cotton answer + comment tells you how to do this with vimdiff.

+5
Oct 13 2018-10-10
source share



All Articles