For some reasons one of my files contains old style Mac line endings (after editing on OSX). These are \"CR\" (carriage return) characters and show up as ^M in git dif
Since the accepted answer, a new way to do this has been introduced.
You can teach git diff
and git log
to run the file through a special command before creating the diff. This is a one-way process, which is just used for generating diffs, and doesn't affect how the files are stored on disk or in your repository.
Create a new diff driver called "cr", which runs the file through tr
before calculating the diff. In your .git/config
:
[diff "cr"]
textconv = tr '\\r' '\\n' <
Alternatively:
git config diff.cr.textconv "tr '\r' '\n' <"
Then tell git to use it using your .gitattributes
(e.g. for all .csv files):
*.csv diff=cr
Note that this only affects diffs. It won't help you with merging!