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?

  • Git: Copy a chain of commits to some other commit, no branches involved, in one command
  • how to control ownership of files auto-pushed to a git target repo by commit hooks?
  • Committing Machine Specific Configuration Files
  • Git merge strategy for Agile Branching workflow
  • How to separate productive/dev environment on a server with git?
  • How to revert changes to 1 file in previous commit
  • Gitolite on Dreamhost
  • Github referring sites traffic number varies
  • How to check if your local git repository is up to date
  • `git log` shows notes that `git notes` doesn't
  • How to pull for all files except one?
  • Is there a way to change the file path for an Rstudio project?
  • 5 Solutions collect form web for “git diff – show me line ending changes?”

    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.

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

    highlights whitespace diffs in changed lines.

    One way to see whitespace changes is to do a character-by-character “word diff” with

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

    This highlights all whitespace changes everywhere in lines. Removed whitespace is wrapped in [- and -] and added whitespace in {+ and +}.

    Alternatively, as suggested by Alex

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

    highlights all whitespace changes at the ends of lines.

    A graphical diff tool will show you the change better — try git difftool.

    Use meld, and set the preferences to show whitespace. (Edit -> Preferences -> Show Whitespace.)

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

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

    git diff | cat -v

    “^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.

    Git Baby is a git and github fan, let's start git clone.