If you're working on Windows, you need to decide what line endings you want in your sandbox, and what line endings you want in your repos. The "right" choice for the autocrlf
setting is not the same for everyone.
autocrlf=false: don't mess with my files!
@VonC's answer is the right answer if you just don't want Git to mess with line endings - an autocrlf
set to false
means take files in and out of Git verbatim.
This is arguably the only correct setting for autocrlf
, because as @VonC pointed out, files like Windows .bat files will get broken by newline conversions, and you really do not want line-end conversions to happen in binary files either (that .jpg file might not be recoverable once you've accidentally done a CRLF->LF conversion on it...)
autocrlf=input: fix my mistakes when I create files
My usual answer on Windows is different, however: in my repos, I want Unix-style newlines, always. But on my Windows machine a number of pesky tools create files with Windows-style newlines. Yes, you can (and should) set your editor to use the right line endings, but an autocrlf
set to input
catches my "mistakes", e.g., when a file is generated by a Python script on a Windows machine, it usually ends up with CRLF line endings. In my Windows configurations, I always use git config --global core.autocrlf input
, and that means my files always get committed with Unix style newlines, but they get checked out as they exist in the repo.
What about .bat and binary files? When this settings causes a conversion, Git issues a warning for me, so if it were to happen on a file where it should not, I'd get a warning and could fix the situation for that commit. I don't remember ever having had a problem with this, however, but my Git repos are pretty much exclusively portable source code and text files where I really, really want LF endings.
I think this is a nice setting if you're working on a Linux- or Mac-oriented project from a Windows PC.
autocrlf=true: I really always want CRLF in my checked out files
I mention this one for completeness, but would generally advise against it. If you always want your files with CRLF line endings when you're working on them, setting autocrlf
to true
will do that, but commit them in Unix-style LF line endings. This makes sense in some cases, but it can cause trouble in many cases.
Make your choice and save it globally
From the message you got, I'm guessing true
was your setting, so you probably want to decide which of false
or input
is best for you, and set that globally, by running one of these two commands in your Git Bash prompt:
git config --global core.autocrlf false
or
git config --global core.autocrlf input
Wish-list for Git developers:
What I would really like is an autocrlf=prompt
setting: ask me what to do any time I try to commit a file with a CRLF in it. I guess I should make myself a pre-commit hook for it...