Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git diff - show me line ending changes?

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?

like image 708
Stonky Avatar asked Oct 13 '10 03:10

Stonky


People also ask

How do I see changes in git diff?

You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch.

What does git diff show you?

The git diff command shows the differences between the files in two commits or between your current repository and a previous commit. This command displays changes denotes by headers and metadata for the files that have changed.

How do I check my git Crlf?

If you want to see the core. autocrlf setting for a particular repository, run git config core. autocrlf inside it. You'll get back the value it's set to, or nothing if it is unset.

Why git diff does not show changes?

Your file is already staged to be committed. You can show it's diff using the --cached option of git. To unstage it, just do what git status suggests in it's output ;) You can check The Git Index For more info.


2 Answers

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.

like image 164
Paul Whittaker Avatar answered Oct 14 '22 03:10

Paul Whittaker


You can see line-ending difference with the following command.

git diff | cat -v 

Then "^M" is printed for CRLF (DOS) ending, nothing for LF (Unix) ending.

Apparently git diff is doing the right thing, printing CR and LF characters for CRLF ending. But because CR is consumed by the console, we cannot see it. By using cat -v, we can make it visible.

like image 24
Kaz Avatar answered Oct 14 '22 01:10

Kaz