In VSCode, I have this pop-up that says:
warning: LF will be replaced by CRLF in <xxx>
I thought it's a warning but my commit didn't go through.
I check and try to find a place to configure GIT inside VSCode. I read some advice like:
git config --get core.autocrlf
I try to find some options in VSCode settings, but I just could not find a way to configure this in VSCode.
What's the correct way to configure this ? Thanks very much.
CodePudding user response:
Outside VSCode, git config --global core.autocrlf false
is a good option, as I mentioned here.
Inside VSCode, make sure the EOL (end of line) indicator (bottom right corner in the status bar) is the right one.
If your file has mixed line ending, there is no option to opt out of line ending normalisation for files, meaning, upon saving a file edited with VS Code, it appears to perform line ending normalisation automatically and without user notification of any sort.
Note: the warning message changes with Git 2.37 (Q3 2022) and becomes:
In the working copy of 'hello.txt', LF will be replaced by CRLF
the next time Git touches it.
CodePudding user response:
If you're working on Windows, you need to decide what line endings you want in your sandbox, and what line endings you want in your repos. The "right" choice for the autocrlf
setting is not the same for everyone.
autocrlf=false: don't mess with my files!
@VonC's answer is the right answer if you just don't want Git to mess with line endings - an autocrlf
set to false
means take files in and out of Git verbatim.
autocrlf=input: fix my mistakes when I create files
My usual answer on Windows is different, however: in my repos, I want Unix-style newlines, always. But on my Windows machine a number of pesky tools create files with Windows-style newlines. Yes, you can (and should) set your editor to use the right line endings, but an autocrlf
set to input
is useful to catch the "mistakes", e.g., when a file is generated by a Python script on a Windows machine, it usually ends up with CRLF line endings. In my Windows configurations, I always use git config --global core.autocrlf input
, and that means my files always get committed with Unix style newlines, but they get checked out as they exist in the repo.
autocrlf=true: I really always want CRLF in my checked out files
I mention this one for completeness, but would generally advise against it. If you always want your files with CRLF line endings when you're working on them, setting autocrlf
to true
will do that, but commit them in Unix-style LF line endings. This makes sense in some cases, but it can cause trouble in many cases.
Make your choice and save it globally
From the message you got, I'm guessing true
was your setting, so you probably want to decide which of false
or input
is best for you, and set that globally, by running one of these two commands in your Git Bash prompt:
git config --global core.autocrlf false
or
git config --global core.autocrlf input