If
core.autocrlf
is set to true, Git will automatically convert Windows
line endings (
0x0D 0x0A
) to Unix line endings (
0x0A
) when adding/commit files to the index/repository and do the reverese when doing the opposite.
The idea of this behavior is to ensure that file hashes stay the same regardless of their line endings.
Example
This example demonstrates the effect of setting core.autocrlf
to input
.
git init --quiet repo
cd repo
… and set the option core.autocrlf
to input
:
git config core.autocrlf input
We create two files, one with a DOS line ending and one with a Unix line ending:
[System.IO.File]::WriteAllBytes("$pwd/unix.txt", ([byte][char] 'f', [byte][char] 'o', [byte][char] 'o', 0x0a ))
[System.IO.File]::WriteAllBytes("$pwd/dos.txt" , ([byte][char] 'f', [byte][char] 'o', [byte][char] 'o', 0x0d, 0x0a ))
git add *.txt
The two files are removed from the
working tree (but not from the index) …
rm *.txt
… and
restored from the index into the working tree:
git restore *.txt
Showing the files's bytes shows that both files now have a Unix line ending:
([System.IO.File]::ReadAllBytes("$pwd/unix.txt") | % { '{0,2:X2}' -f $_ }) -join ' '
([System.IO.File]::ReadAllBytes("$pwd/dos.txt" ) | % { '{0,2:X2}' -f $_ }) -join ' '