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?
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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With