git and CR vs LF (but NOT CRLF) git and CR vs LF (but NOT CRLF) git git

git and CR vs LF (but NOT CRLF)


Git doesn’t appear to support CR line endings, so I would write a filter to convert the newlines. The files in the work tree will have CR line endings, and they will be transparently converted to LF when they are indexed. The filter has two parts: “clean” checks the files in, and “smudge” checks the files out.

Use this in .git/config:

[filter "cr"]    clean = tr '\\r' '\\n'    smudge = tr '\\n' '\\r'

And .git/info/attributes (or .gitattributes if it should be versioned)

* filter=cr

Note that this automatically makes git-diff happy, since it will use the “clean” version.

Just remember to set the pattern to just the files you need, or binary files will be corrupted and all text files will check out with CR line endings.

Also note that if the filter is not configured, it will silently fail, so add the config line when setting up a new copy of the repository.


FWIW, I ended up converting the line endings to LF on the local side of things. It ended up being the simpler/less buggy solution.