Doubt regarding core.autocrlf

I am on Windows. The settings was set to “input” by default. It was converting all files into LF (though not in the working directory) when I did “git add .” and then not converting them back to CRLF when I checked them out.

So I changed it to “true”, as instructed by the git guide: “If you’re on a Windows machine, set it to true — this converts LF endings into CRLF when you check out code”. But when I do this, if I create a repo that has some LF files (like library/framework files I’ve got from github), it tells me when I do “git add .” that it’s replacing LF with CRLF in all of those files. What is the point of that? Why not leave them as LF?

1 Like

@shacp wrote:

I am on Windows. The settings was set to “input” by default. It was converting all files into LF (though not in the working directory) when I did “git add .” and then not converting them back to CRLF when I checked them out.

 

So I changed it to “true”, as instructed by the git guide: “If you’re on a Windows machine, set it to true — this converts LF endings into CRLF when you check out code”. But when I do this, if I create a repo that has some LF files (like library/framework files I’ve got from github), it tells me when I do “git add .” that it’s replacing LF with CRLF in all of those files. What is the point of that? Why not leave them as LF?

The message you’re seeing is a feature of Git, designed to handle line ending differences across operating systems. We have more information about managing line endings in this help article:

https://help.github.com/articles/dealing-with-line-endings/

You can use the settings described in that article to tell Git how to handle your line endings. If you’re developing on Windows for a Windows-only project, you can disable automatic line ending handling in Git using this command:

`git config --global core.autocrlf false```

https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#_code_core_autocrlf_code

However, if you’re working on these files on other systems (or working with other collaborators who use non-Windows systems), this approach is not recommended.

I hope this helps!

1 Like