So, I always thought that with core.autocrlf=true
Git replaces all LF
endings with CRLF
when checking out the file into the working directory.
From the Git book:
If you’re on a Windows machine, set it to true – this converts LF endings into CRLF when you check out code
However, when checking out a file with mixed line endings and core.autocrlf
set to true
, my version of Git checks out the file as-is.
I've found a very convenient GitHub repository to test this behaviour - https://github.com/YueLinHo/TestAutoCrlf
Test results:
- A file with
LF
endings only (LF.txt)- With
autocrlf=false
: checked out as-is (all line endings areLF
) - With
autocrlf=true
: all line endings are changed toCRLF
on checkout
- With
So far so good, everything as I expected. Now for the file with mixed line endings:
- A file with mixed line endings (MIX-more_CRLF.txt, MIX-more_LF.txt)
- With
autocrlf=false
: checked out as-is (a mix ofLF
andCRLF
) - With
autocrlf=true
: checked out as-is (a mix ofLF
andCRLF
)
- With
Why does this happen? I haven't seen anything about autocrlf=true
not touching files with mixed line endings.
Are my Git settings at fault? I checked the core.autocrlf
setting running git config --get core.autocrlf
in the repository folder after checking out with autocrlf=true
in the global .gitconfig, and the command returned true. There is no .gitattributes file to overwrite the settings.
All tests were made on Git version 1.9.5.msysgit.0
.
EDIT: Same behaviour on the latest msysgit version 1.9.5.msysgit.1
.
My original problem is that I somehow managed to commit a mixed-line ending file with only LF
endings while having core.autocrlf
set to true
, meaning the file was checked out as-is, but commited with CRLF
changed to LF
. I'm currently working from another machine and cannot reproduce this behaviour on my msysgit version.