Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git still shows “LF will be replaced by CRLF” warning when autocrlf is false and text is unspecified

Tags:

git

windows

I have a repo that will only ever be used on Windows. And I would prefer that source control does not modify the contents of my files in any way.

I set core.autocrlf to false in global settings and verified that no local repo override was present. I found that there was an existing .gitattributes file in my repo with * text=auto as the only entry. So I deleted the .gitattributes file. From reading the documentation, my understanding is that this should result in text being unspecified, and will follow the behavior set for core.autocrlf.

However, I still get the following error when I stage my files:

LF will be replaced by CRLF in MyProject/src/static/images/logo.svg.
The file will have its original line endings in your working directory.

If I understand correctly, there's something that still modifies my files. What is it and how can I stop it?

like image 319
Hele Avatar asked Oct 15 '22 01:10

Hele


People also ask

How do I change from CRLF to LF in Git?

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. You should use this for files that must keep LF endings, even on Windows.

What does LF will be replaced by CRLF mean?

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.

What is Autocrlf in Git?

autocrlf . This is a similar approach to the attributes mechanism: the idea is that a Windows user will set a Git configuration option core. autocrlf=true and their line endings will be converted to Unix style line endings when they add files to the repository.

What does Autocrlf true do?

autocrlf = true This means that Git will process all text files and make sure that CRLF is replaced with LF when writing that file to the object database and turn all LF back into CRLF when writing out into the working directory.


1 Answers

First, as I mentioned in "Windows git “warning: LF will be replaced by CRLF”, is that warning tail backward?", make sure to:

  • use a recent Git for Windows (more than 2.19 at the very least)
  • set git config --global core.autocrlf false (you have done so, as specified in your question: good)
    Since you don't have a .gitattributes file, there is no text attribute for svg files:

    If the text attribute is unspecified, Git uses the core.autocrlf configuration variable to determine if the file should be converted.

Second, check if an add --renormalize would help

git add --renormalize .
git commit -m "Introduce end-of-line final normalization if needed"
git push

Then check if a new clone of the repository would still ehibit the same message.


Note: the warning message has changed with Git 2.37 (Q3 2022).

like image 53
VonC Avatar answered Oct 19 '22 00:10

VonC