How to turn off Git warnings "LF will be replaced by CRLF"?
Asked Answered
I

4

18

I am working on Windows, but may also work on Unix, so I don't need to store Windows line endings. I just want to suppress the warning.

I found these related Stack Overflow questions:

I tried the following:

git config core.whitespace cr-at-eol false<Br>
git config core.whitespace cr-at-eol true<br>
git config core.whitespace cr-at-eol nowarn

But these don't seem to do anything. Does anyone know how to turn off the warnings?

Interpolate answered 25/10, 2011 at 17:52 Comment(1)
L
9

I simply use autocrlf=true in the .git/config file to cover most situations in Windows. There are occasional warnings depending on new source files.

If you have special files that don't follow the scheme set up a .gitattributes separately for them e.g. I have Matlab files with *.m eol=lf.

Leveret answered 26/10, 2011 at 23:10 Comment(2)
In order to elaborate for total git newbies like me: the file "config" is in the .git directory. On Windows, the directory's "hidden" attribute is set.Cover
This doens't turn off the warnings. It changes gits automatic line-ending conversion to check textish files into git with LF and to check them out CLRF line-endings. It's also unsual to set this up per repo. Instead you're going to get warnings when checking in your CLRF files that they will be replaced by LFAnole
G
6

I used this way:

The git config core.autocrlf command is used to change how Git handles line endings. It takes a single argument.

On Windows, you simply pass true to the configuration. For example:

$ git config --global core.autocrlf true    
# Configure Git on Windows to properly handle line endings

You can also provide a special --global flag, which makes Git use the same settings for line endings across every local Git repository on your computer.

After you've set the core.autocrlf option and committed a .gitattributes file, you may find that Git wants to commit files that you have not modified. At this point, Git is eager to change the line endings of every file for you.

The best way to automatically configure your repository's line endings is to first backup your files with Git, delete every file in your repository (except the .git directory), and then restore the files all at once. Save your current files in Git, so that none of your work is lost.

$ git add . -u
$ git commit -m "Saving files before refreshing line endings"

Remove every file from Git's index.

$ git rm --cached -r .

Rewrite the Git index to pick up all the new line endings.

$ git reset --hard

Add all your changed files back, and prepare them for a commit. This is your chance to inspect which files, if any, were unchanged.

$ git add .
# It is perfectly safe to see a lot of messages here that read
# "warning: CRLF will be replaced by LF in file."

Commit the changes to your repository.

$ git commit -m "Normalize all the line endings"

source: https://help.github.com/articles/dealing-with-line-endings/

Glitter answered 31/7, 2015 at 14:3 Comment(1)
This answer also does not turn off the warnings, it changes how handles the line-ending of files that it check in and out. This is the correct answer https://mcmap.net/q/13123/-with-git-how-do-i-turn-off-the-quot-lf-will-be-replaced-by-crlf-quot-warningAnole
A
3

You can turn off the warning with

git config --global core.safecrlf false

(This will only turn off the warning, not the function itself.)

https://mcmap.net/q/13123/-with-git-how-do-i-turn-off-the-quot-lf-will-be-replaced-by-crlf-quot-warning


The question is how to turn-off the warnings generated when checking files into Git when a line-ending conversion is set using autocrlf.

These are warnings that line-endings will not be preserved. Ie. you had a file in a specific state, you are checking that into Git and you shouldn't expect it to be in that exact state when you check it out at some other time. Or, if someone else checks it out.

If you change the setting of core.autoclrf, you're just changing the setting of which format you want the files checked out as and by extension, flipping the warning to "CRLF will be replaced by LF". Unless you change it to input, which in most cases turns things into a mess.

Whether or not line-endings are significant depends on the project and should be set project wide, using .gitattributes.

Anole answered 10/6, 2021 at 13:54 Comment(1)
I'm surprised this answer doesn't get more upvotes; it is the only answer that correctly answers the original question. The core.autocrlf setting concerns how line endings are handled, which is different from what is being asked, it is indeed the core.safecrlf setting that addresses the warnings themselves.Induline
S
2

I'm also developing on windows and Because our servers are powered by Linux and all the code has to base on Linux I have preferred to change all my files to LF instead of CRLF.

from git command line:

git config --global core.autocrlf false

i'm working with intellij idea so it's quite easy:

1) File --> settings --> editor --> code style: (for any new file will be created)

a. Scheme : default

b. Line separator: unix and os x (\n)

2) mark the root of the project --> file --> line separator --> LF unix and os x (\n) (for exist files)

Remark: you can also use apps like dos2unix.exe or some other scripts.

than I did using my command line: (you can do this also from the idea)

git commit -m "bla bla"
git add .
git push origin master

since then, I didn't got those warnings

Sldney answered 15/11, 2017 at 13:32 Comment(1)
This answer turn off the warnings either. It changes how git treats the line-endings of files that are checked-in/checked-out.Anole

© 2022 - 2024 — McMap. All rights reserved.