Skip to content

Instantly share code, notes, and snippets.

@NateWeiler
Last active November 14, 2024 16:55
Show Gist options
  • Save NateWeiler/df202280ce8cc38e9f00dbc17708fab2 to your computer and use it in GitHub Desktop.
Save NateWeiler/df202280ce8cc38e9f00dbc17708fab2 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 {} \;
@duboisp
Copy link

duboisp commented Aug 21, 2023

The warning can be also triggered when the line ending do not match the one specified in the .gitattributes file with the option eol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment