Git under Windows reports an error: warning: LF will be replaced by CRLF in ××××.××

 

Git under Windows reports an error:

warning: LF will be replaced by CRLF in ××××.××(file name)
The file will have its original line ending in your working directory.

translation:
LF will be replaced by CRLF in the xxx.xx file.
In the working directory, this file will keep its original newline character. (Line ending: end of line, newline)

 annotation:

          LF: Line feed wrap

          CRLF: Carriage Return Line Feed Carriage Return Line Feed

 

1. Under different operating systems, the methods of handling end-of-line characters are different :

  Windows: CRLF (representing two characters with carriage return and line feed at the end of the sentence, that is, “\r\n” line feed under windows)

       Under unix: LF (represents the end of a sentence, only use line breaks)

       Mac: CR (represents only carriage return)

2. Handling “line ending” under Git

  core.autocrlf is the variable responsible for processing line ending in git. You can set 3 values: true, false, and inout.

(1) Set to true [config –global core.autocrlf  true ]

          When set to true, it means that whenever you add a file to the git repository, git will treat it as a text file.

   It will turn crlf into LF.

(2) Set to false [config –global core.autocrlf  false ]

     When set to false, line endings will not be converted. The text file remains as it is.

(3) When set to input, when adding a file git warehouse, git programs crlf to lf. When someone checks the code, it is still the lf way. Therefore, do not use this setting under the window operating system.

 


 

In summary, the reasons for the above warning are:

  The line break in windows is CRLF, and the line break in Linux is LF (using the Git command line Git Bash, which is actually equivalent to the linux environment), so this error message will appear when you execute the git add xxx.xx operation!

Solution: (Note: The warehouse will be deleted! The warehouse will be deleted! The warehouse will be deleted!)

  <1>Delete .git 【rm -rf .git

  <2>Disable automatic conversion, and set it soon: git config –global core.autocrlf  false

         Re-initialize and perform the add operation:

  <3>【git init

  <4> 【git add xxx.xx

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *