env:
Wheng I git commit
, it says:
warning: LF will be replaced by CRLF.
Is this warning tail backward?
I edit file in Windows, the end of line is CRLF
, just like this pic:
And git changes it to LF
for committing to repo.
So I think the correct warning is:
warning: CRLF will be replaced by LF.
This question is related to
git
git config --global core.autocrlf false
works well for global settings.
But if you are using Visual Studio, might also need to modify .gitattributes
for some type of projects (e.g c# class library application):
* text=auto
--Update on 9th July---
Removed "It is correct and accurate" as commented by @mgiuca
======
NO. It is NOT talking about your files currently with CRLF
. It is instead talking about files with LF
.
It should read:
warning: (If you check it out/or clone to another folder with your current core.autocrlf configuration,)LF will be replaced by CRLF
The file will have its original line endings in your (current) working directory.
YES the warning is backwards.
And in fact it shouldn't even be a warning in the first place. Because all this warning is saying (but backwards unfortunately) is that the CRLF characters in your file with Windows line endings will be replaced with LF's on commit. Which means it's normalized to the same line endings used by *nix and MacOS.
Nothing strange is going on, this is exactly the behavior you would normally want.
This warning in it's current form is one of two things:
;)
All of this assumes core.autocrlf=true
Original error:
warning: LF will be replaced by CRLF
The file will have its original line endings in your working directory.
What the error SHOULD read:
warning: LF will be replaced by CRLF in your working directory
The file will have its original LF line endings in the git repository
Explanation here:
The side-effect of this convenient conversion, and this is what the warning you're seeing is about, is that if a text file you authored originally had LF endings instead of CRLF, it will be stored with LF as usual, but when checked out later it will have CRLF endings. For normal text files this is usually just fine. The warning is a "for your information" in this case, but in case git incorrectly assesses a binary file to be a text file, it is an important warning because git would then be corrupting your binary file.
Basically, a local file that was previously LF will now have CRLF locally
After I set core.autocrlf=true
I was getting "LF will be replaced by CRLF" (note not "CRLF will be replaced by LF") when I was git add
ing (or perhaps it was it on git commit
?) edited files in windows on a repository (that does use LF) that was checked out before I set core.autocrlf=true
.
I made a new checkout with core.autocrlf=true
and now I'm not getting those messages.
Do just simple thing:
If you are using Visual Studio 2017, 2019, you can:
[core]
autocrlf = false
[filter "lfs"]
required = true
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
Source: Stackoverflow.com