Search notes:

Git option: core.autocrlf

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.
When setting core.autocrlf to false, no modification of line endings takes place.
As per sthis stackoverflow answer, core.autocrlf should be to false because the value of core.autocrlf
The eol directive in .gitattributes is therefore the preferred alternative.
core.autocrlf can also be set to input which only does the conversion from Dos to Unix line endings when commiting but not on when getting a file from the repository into the working tree.
The default value of core.autocrlf is false.

Example

This example demonstrates the effect of setting core.autocrlf to input.
First, we initialize a new repository for this demonstration …
git init   --quiet  repo 
cd                  repo
Github repository about-git, path: /options/core/autocrlf/init.ps1
… and set the option core.autocrlf to input:
git config core.autocrlf input
Github repository about-git, path: /options/core/autocrlf/config.ps1
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 ))
Github repository about-git, path: /options/core/autocrlf/create-files.ps1
These files are then added to the index:
git add *.txt
Github repository about-git, path: /options/core/autocrlf/add.ps1
The two files are removed from the working tree (but not from the index) …
rm *.txt
Github repository about-git, path: /options/core/autocrlf/rm.ps1
… and restored from the index into the working tree:
git restore *.txt
Github repository about-git, path: /options/core/autocrlf/restore.ps1
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 ' '
Github repository about-git, path: /options/core/autocrlf/show-bytes.ps1

See also

The influence of the value of core.autocrlf on calculating file hashes with git hash-object.
The core.safecrlf option.
Other Git options.

Index