Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save imanimanyara/2ce93d89a8391c64f407e884d5e9a4f3 to your computer and use it in GitHub Desktop.
Save imanimanyara/2ce93d89a8391c64f407e884d5e9a4f3 to your computer and use it in GitHub Desktop.
How to turn off the “CRLF will be replaced by LF” warning

How to turn off the “CRLF will be replaced by LF” warning

CRLF: Line breaks in windows environment

LF : Line breaks in linux environment

The meaning of this error is that there are two newline characters in the file, git will automatically replace CRLF with LF, so a warning is given.

warning: CRLF will be replaced by LF in [File] . The file will have its original line endings in your working directory.

Turn the auto-conversion feature off in the settings

$ git config --global core.autocrlf false

Perform a safecrlf check when the file is submitted.

Refuse to submit a file containing a mixed line break

$ git config --global core.safecrlf true   

Allow submission of files containing mixed line breaks

$ git config --global core.safecrlf false   

Warning when submitting a file containing mixed line breaks

$ git config --global core.safecrlf warn

Convert to LF when submitting, convert to CRLF when checked out

$ git config --global core.autocrlf true

Convert all CRLF line endings to LF before it stores it in the commit:

$ git config --global core.autocrlf input

then

$ git rm --cached -r . && git reset --hard # Warning, your local changes will be lost, so commit FIRST

Add the following to your .gitattributes file

$ echo "* text=auto" >>.gitattributes

Convert Cloned Files with CRLF line endings to LF and to update the .gitattributes file to auto enforce the LF line endings.

find . -type f -exec dos2unix {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment