git add throws warning "CRLF will be replaced by LF in <file-name>"
Asked Answered
S

1

10

I started working on a Xamarin crossplatform development recently. While some of devs in my team are using Mac for development (with Visual Studio for Mac), others are using Windows (with Visual Studio 2017). We use git/github as our code repository/version control system.

After I did some changes and added some new files, I issued git add . to stage all my changes but I got warnings like this

warning: CRLF will be replaced by LF in <file-name>.
The file will have its original line endings in your working directory

I checked my git config and core.autocrlf=input which to my understanding and according to documentation here https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration, is correct setting for Mac.

However, I am unsure about the warning above since I have never seen it before. I find it even more confusing since not all of files I added are showing this warning but only some.

I have read numerous posts about this issue but none seam to clearly explain if these warnings can or cannot be ignored. Or if they need to be fixed and how to fix them for teams that use both Windows and MacOS like mine team does.

Do I need to worry about this warning and what does it exactly mean for teams like mine working on both Windows and MacOS machines?

Slam answered 13/11, 2018 at 23:28 Comment(0)
D
10

I would still recommend:

git config core.autocrlf false
git add --renormalize .
git commit -m "Do not touch eol"

If you can, avoid Git making any change to your eol, and work with editors which respect the eol of the file being edited.

Devisor answered 14/11, 2018 at 6:6 Comment(5)
Could you elaborate bit? Why not change if you work on Mac and others are on Windows? etc? ThanksSlam
@Slam Because both Mac and Windows can work with the same files in \n eol (\r\n is not needed) So no need for Git to touch anything.Devisor
according to hit documentation git-scm.com/book/en/v2/Customizing-Git-Git-Configuration, you should not use false in cross-platform teams thoughSlam
@Slam That doc is old and now not accurate, even obsolete. It doesn't even mention core.safecrlf (git-scm.com/docs/git-config#git-config-coresafecrlf). As I have been saying the past 8 years (https://mcmap.net/q/11232/-definitive-recommendation-for-git-autocrlf-settings, https://mcmap.net/q/11223/-why-should-i-use-core-autocrlf-true-in-git), eol should be managed through .gitattributes core.eol directive, not the all-encompassing core.autocrlf, which modifies everything.Devisor
@Slam I didn't see your edit in your question, but you are referencing an obsolete documentation.Devisor

© 2022 - 2024 — McMap. All rights reserved.