I have a Git repository that is accessed from both Windows and OS X, and that I know already contains some files with CRLF line-endings. As far as I can tell, there are two ways to deal with this:
Set core.autocrlf
to false
everywhere,
Follow the instructions here (echoed on GitHub's help pages) to convert the repository to contain only LF line-endings, and thereafter set core.autocrlf
to true
on Windows and input
on OS X. The problem with doing this is that if I have any binary files in the repository that:
they will be corrupted. It is possible my repository contains such files.
So why shouldn't I just turn off Git's line-ending conversion? There are a lot of vague warnings on the web about having core.autocrlf
switched off causing problems, but very few specific ones; the only that I've found so far are that kdiff3 cannot handle CRLF endings (not a problem for me), and that some text editors have line-ending issues (also not a problem for me).
The repository is internal to my company, and so I don't need to worry about sharing it with people with different autocrlf settings or line-ending requirements.
Are there any other problems with just leaving line-endings as-is that I am unaware of?
autocrlf . This is a similar approach to the attributes mechanism: the idea is that a Windows user will set a Git configuration option core. autocrlf=true and their line endings will be converted to Unix style line endings when they add files to the repository.
The git config core. autocrlf command is used to change how Git handles line endings. It takes a single argument. On macOS, you simply pass input to the configuration. For example: $ git config --global core.autocrlf input # Configure Git to ensure line endings in files you checkout are correct for macOS.
Whereas Windows follows the original convention of a carriage return plus a line feed ( CRLF ) for line endings, operating systems like Linux and Mac use only the line feed ( LF ) character. The history of these two control characters dates back to the era of the typewriter.
core.autocrlf = input This means that Git will process all text files and make sure that CRLF is replaced with LF when writing that file to the object database. It will not, however, do the reverse.
The only specific reasons to set autocrlf
to true
are:
git status
showing all your files as modified
because of the automatic EOL conversion done when cloning a Unix-based EOL Git repo to a Windows one (see issue 83 for instance)Unless you can see specific treatment which must deal with native EOL, you are better off leaving autocrlf
to false
(git config --global core.autocrlf false
).
Note that this config would be a local one (because config isn't pushed from repo to repo)
If you want the same config for all users cloning that repo, check out "What's the best CRLF
handling strategy with git?", using the text
attribute in the .gitattributes
file.
Example:
*.vcproj text eol=crlf *.sh text eol=lf
Note: starting git 2.8 (March 2016), merge markers will no longer introduce mixed line ending (LF) in a CRLF file.
See "Make Git use CRLF on its “<<<<<<< HEAD” merge lines"
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