Windows git ": LF will be replaced by CRLF", is this a warning tail back?

okr:

  • Windows 7
  • msysgit

When g i git commit , it says:

 warning: LF will be replaced by CRLF. 

Is this warning tail backwards?
I am editing a file in Windows, the end of the CRLF line, like this picture:
enter image description here
And git changes it to LF for a repo.
Therefore, I think the correct warning is:

 warning: CRLF will be replaced by LF. 
+121
git
Jul 13. '13 at 8:12
source share
7 answers

warning: LF will be replaced by CRLF.

Depending on which editor you use, a text file with LF will not necessarily be saved with CRLF: recent editors may preserve the eol style. But this git config setting insists on changing these ...

Just make sure (as I recommend here ):

 git config --global core.autocrlf false 

This way you avoid any automatic conversions and you can specify them with the .gitattributes file of the core.eol directives .




Windows Git "LF will be replaced by CRLF"
Is this warning tail back?

No: you are on Windows and the git config help page is not mentioned

Use this option if you want CRLF line endings in your working directory even if there are no normalized line endings in the repository.

As described in " git replacing LF with CRLF ", this should only happen when fetching (not commit), with core.autocrlf=true .

  repo / \ crlf->lf lf->crlf / \ 

As mentioned in XiaoPeng's answer , this warning is similar:

warning: (If you check it or clone to another folder with the current core.autocrlf configuration,) LF will be replaced by CRLF
The file will have the original line endings in your (current) working directory.

As mentioned in git-for-windows/git release 1242 :

I still feel this message is confusing, the message can be expanded to include a better explanation of the problem, for example: "LF will be replaced with CRLF in file.json after deleting the file and checking it again."

Note: Git 2.19 (September 2018) when core.autocrlf used, core.autocrlf “LF will be replaced by CRLF” is now suppressed .




As Quailar rightly comments , if the conversion occurs at commit , then only in LF .

This particular 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 /* ie SAFE_CRLF_FAIL */ die("LF would be replaced by CRLF in %s", path); 

It is called convert.c#crlf_to_git() , it is called convert.c#crlf_to_git() itself, convert.c#convert_to_git() convert.c#renormalize_buffer() .

And this last renormalize_buffer() is only called using merge-recursive.c#blob_unchanged() .

Therefore, I suspect that this conversion occurs in git commit only if the specified commit is part of the merge process.




Note: in Git 2.17 (Q2 2018), clearing the code adds some clarification.

See Commit 8462ff4 (January 13, 2018) of Torsten Begershausen ( tboegi ) .
(Combined by Junio ​​K Hamano - gitster - in commit 9bc89b1 , February 13, 2018)

convert_to_git (): safe_crlf / checkafe becomes int conv_flags

When calling convert_to_git() the checksafe parameter determined what should happen if the EOL conversion ( CRLF --> LF --> CRLF ) does not perform purely cyclic processing.
In addition, he also determined whether to renormalize line endings ( CRLF --> LF ) or leave them as they are.

checkafe was a safe_crlf listing with the following 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 the regression introduced in 8462ff4 (" convert_to_git() : safe_crlf/checksafe becomes int conv_flags ", 2018-01-13, Git 2.17.0) as early as the Git 2.17 loop forced autocrlf rewrite so that autocrlf warned despite setting safecrlf=false ,

See Commit 6cb0912 (June 04, 2018) by Anthony Sottil ( asottile ) .
(Combined Junio ​​C Hamano - gitster - in commit 8063ff9 , June 28, 2018)

+151
Jul 13 '13 at 8:18
source share

YES warning back.

And in fact, this should not even be a warning in the first place. Because all this warning says (but, unfortunately, vice versa) that the CRLF characters in your file with the end of the Windows line will be replaced by LF with commit. This means that it normalizes to the same line endings used by * nix and MacOS.

Nothing strange happens, this is exactly the behavior that you usually would like.

This warning in this current form is one of two things:

  • Unfortunate error combined with an overly cautious warning message, or
  • A very smart conspiracy to make you really think about it ...

;)

+20
Jun 30 '16 at 0:07
source share

--Update 9th July ---

Removed "This is correct and accurate," as @mgiuca commented

======

No. This does not say about your files currently with CRLF . Instead, we are talking about files with LF .

It should be read:

warning: ( If you check it or clone to another folder with the current core.autocrlf configuration ,) LF will be replaced by CRLF

The file will have the original line endings in your ( current ) working directory.

This picture should explain what it means. enter image description here

+15
Jun 16 '17 at 6:09
source share

All this assumes core.autocrlf=true

Original error:

warning: LF will be replaced by CRLF
The file will have the original line endings in your working directory.

WHAT TO READ A MESSAGE:

warning: LF will be replaced by CRLF in your working directory
The file will have the original LF ends in the git repository

The explanation is here :

A side effect of this convenient conversion, and this is what warns you about, is that if the text file you created originally had LF endings instead of CRLF, it will be stored with LF as usual, but after that it will have CRLF endings. For normal text files, this is normal. The warning is “for your information” in this case, but in case git incorrectly evaluates the binary as a text file, this is an important warning because git will distort your binary.

Basically, a local file that was previously LF now has local CRLF

+10
Nov 24 '16 at 15:37
source share

git config --global core.autocrlf false works well for global settings.

But if you are using Visual Studio, you may also need to modify .gitattributes for some types of projects (for example, a C # class library application):

  • delete line * text=auto
+4
Jun 13 '18 at 3:32
source share

After I set core.autocrlf=true , I got “LF will be replaced by CRLF” (note that “CRLF will be replaced by LF”) when I was git add ing (or maybe it was on git commit ? ) edited the files in the windows in the repository (which uses LF), which was core.autocrlf=true out before I set core.autocrlf=true .

I did a new checkout with core.autocrlf=true , and now I do not receive these messages.

+1
Jun 03 '15 at 15:18
source share

Do just the simple thing: 1. Open git-hub (Shell) and browse to the directory file belonging to (cd / a / b / c / ...) 2. Run dos2unix (sometimes dos2unix.exe) 3. Try now. If you get the same error again. Follow all the steps above except instead of dos2unix, do unix2dox (unix2dos.exe someday)

0
May 26 '16 at
source share



All Articles