I've found tons of sites that explain how to have git warn you when you're changing line endings, or miscellaneous other techniques to prevent you from messing up an entire file. Assume it's too late for that -- the tree already has commits that toggle the line endings of files, so git diff shows the subtraction of the old file followed by the addition of a new file with the same content

I'm looking for a git configuration option or command-line flag that tells diff to just ignore those -- if two lines differ only by whitespace, pretend they're the same. I need this config option/flag to work for anything that relies on file differences -- diff, blame, even merge/rebase ideally -- I want git to completely ignore trailing whitespace, particularly line endings. How can I do that?

1 Answer 1


For diff, there's git diff --ignore-space-at-eol, which should be good enough. For diff and blame, you can ignore all whitespace changes with -w: git diff -w, git blame -w.

For git apply and git rebase, the documentation mentions --ignore-whitespace.

For merge, it looks like you need to use an external merge tool. You can use this wrapper script (untested), where favorite-mergetool is your favorite merge tool; run git -c mergetool.nocr.cmd=/path/to/wrapper/script merge. The result of the merge will be in unix format; if you prefer another format, convert everything to that different format, or convert $MERGED after the merge.

set -e
tr -d '\013' <"$BASE" >"$TEMP"
mv -f "$TEMP" "$BASE"
tr -d '\013' <"$LOCAL" >"$TEMP"
mv -f "$TEMP" "$LOCAL"
tr -d '\013' <"$REMOTE" >"$TEMP"
mv -f "$TEMP" "$REMOTE"
favorite-mergetool "$@"

To minimize trouble with mixed line endings, make sure text files are declared as such.

See also Is it possible for git-merge to ignore line-ending differences? on Stack Overflow.

  • Is there any configuration to always use the -w flag with git blame?
    – Thayne
    Feb 11, 2015 at 17:02
  • @Thayne Not that I know of. You can define an alias like bl = blame -w but you can't redefine the name of built-in commands and I don't see a configuration option to make it the default. But I am not a git expert. Feb 11, 2015 at 17:06
  • 2
    for git status ?
    – Ejaz
    Oct 25, 2018 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.