This problem arises if you use UNIX based system (macOS) to push code, the code will have an LF ending. If you use a windows machine, make modifications to the code, and do commit, it will be replaced by CRLF since git is smart and does not expect you to use LF on Windows OS.
You can set the mode to use by adding an additional parameter of true or false to the above command line. If core. autocrlf is set to true, that means that any time you add a file to the Git repository that Git thinks is a text file, it will turn all CRLF line endings to just LF before it stores it in the commit.
This is a good default option. text eol=crlf Git will always convert line endings to CRLF on checkout. You should use this for files that must keep CRLF endings, even on OSX or Linux. text eol=lf Git will always convert line endings to LF on checkout.
In Unix systems the end of a line is represented with a line feed (LF). In windows a line is represented with a carriage return (CR) and a line feed (LF) thus (CRLF). when you get code from git that was uploaded from a unix system they will only have an LF.
warning: LF will be replaced by CRLF.
Depending on the editor you are using, a text file with LF wouldn't necessary be saved with CRLF: recent editors can preserve eol style. But that git config setting insists on changing those...
Simply make sure that (as I recommend here):
git config --global core.autocrlf false
That way, you avoid any automatic transformation, and can still specify them through a .gitattributes
file and core.eol
directives.
windows git "LF will be replaced by CRLF"
Is this warning tail backward?
No: you are on Windows, and the git config
help page does mention
Use this setting if you want to have
CRLF
line endings in your working directory even though the repository does not have normalized line endings.
As described in "git replacing LF with CRLF", it should only occur on checkout (not commit), with core.autocrlf=true
.
repo
/ \
crlf->lf lf->crlf
/ \
As mentioned in XiaoPeng's answer, that warning is the same as:
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.
As mentioned in git-for-windows/git
issue 1242:
I still feel this message is confusing, the message could be extended to include a better explanation of the issue, for example: "LF will be replaced by CRLF in
file.json
after removing the file and checking it out again".
Note: Git 2.19 (Sept 2018), when using core.autocrlf
, the bogus "LF
will be replaced by CRLF" warning is now suppressed.
As quaylar rightly comments, if there is a conversion on commit, it is to LF
only.
That specific warning "LF will be replaced by CRLF
" comes from convert.c#check_safe_crlf():
if (checksafe == SAFE_CRLF_WARN)
warning("LF will be replaced by CRLF in %s.
The file will have its original line endings
in your working directory.", path);
else /* i.e. SAFE_CRLF_FAIL */
die("LF would be replaced by CRLF in %s", path);
It is called by convert.c#crlf_to_git()
, itself called by convert.c#convert_to_git()
, itself called by convert.c#renormalize_buffer()
.
And that last renormalize_buffer()
is only called by merge-recursive.c#blob_unchanged()
.
So I suspect this conversion happens on a git commit
only if said commit is part of a merge process.
Note: with Git 2.17 (Q2 2018), a code cleanup adds some explanation.
See commit 8462ff4 (13 Jan 2018) by Torsten Bögershausen (tboegi
).
(Merged by Junio C Hamano -- gitster
-- in commit 9bc89b1, 13 Feb 2018)
convert_to_git(): safe_crlf/checksafe becomes int conv_flags
When calling
convert_to_git()
, thechecksafe
parameter defined what should happen if the EOL conversion (CRLF --> LF --> CRLF
) does not roundtrip cleanly.
In addition, it also defined if line endings should be renormalized (CRLF --> LF
) or kept as they are.checksafe was an
safe_crlf
enum with these values:
SAFE_CRLF_FALSE: do nothing in case of EOL roundtrip errors
SAFE_CRLF_FAIL: die in case of EOL roundtrip errors
SAFE_CRLF_WARN: print a warning in case of EOL roundtrip errors
SAFE_CRLF_RENORMALIZE: change CRLF to LF
SAFE_CRLF_KEEP_CRLF: keep all line endings as they are
Note that a regression introduced in 8462ff4 ("convert_to_git()
:
safe_crlf/checksafe
becomes int conv_flags
", 2018-01-13, Git 2.17.0) back in Git 2.17 cycle caused autocrlf
rewrites to produce a warning message
despite setting safecrlf=false
.
See commit 6cb0912 (04 Jun 2018) by Anthony Sottile (asottile
).
(Merged by Junio C Hamano -- gitster
-- in commit 8063ff9, 28 Jun 2018)
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:
;)
--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.
This picture should explain what it means.
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
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
This happens because the configuration for GitHub Desktop on Windows assumes CRLF but the text editor may be using LF. You can change your local repository settings to use lf
instead.
Navigate to the root of the git repo and execute this in exact same order
git config core.eol lf
git config core.autocrlf input
Source: GitHub issue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With