Our repository uses LF
, my Git for Windows installation uses Checkout as-is, commit Unix-style line endings,
but I still end up with wall of errors in every file I checkout in my IDE as it still receives CRLF
all the time even though it does support LF
and is configured to use LF
via checked in .editorconfig
file (or in its own settings).:
.editorconfig
root = true
[*]
end_of_line = lf
It is 2020 already and IDEs and tooling already support
LF
on Windows, so how can I have the nice things too?
There are two git config attributes that affect the line endings: core.autocrlf
and core.eol
.
Previously, you were told to use core.autocrlf = true
to be able to work on cross-platform projects, but it's not true
any more.
If your system/IDE/tooling support LF
and you do want to use LF
as everyone else in your team without any silent lf->crlf->lf
normalizations, you must turn off autocrlf
and configure eol
to not infer native
line endings, but force it to use lf
.
LF
in all your files a/o repos:.gitattributes
file.I personally recommend to go with both for all local repos and to ensure cross-platform cross-dev consistency.
Being in your working directory (your local repo):
First commit everything
Let's be paranoid a bit and set it both globally and in repo as well. Just in case.
git config --global core.eol lf
git config --global core.autocrlf false
git config core.eol lf
git config core.autocrlf false
Delete everything "code" except .git
.
You can also omit dependencies, installed files (such as node_modules
), build files and any git-ignored file as well.
and lastly run
git reset --hard HEAD
Things should be working now. Newly checked files should follow the new configuration and keep whatever line-endings were cloned from the remote repo.
Note that if your remote repo uses mix of crlf
lf
endings, you will also have to run and push
git add --renormalize .
.gitattributes
fileBeing in your working directory (your local repo):
Create .gitattributes
file in the root with this content:
* text=auto eol=lf
Commit the file (and everything else)
Same as above
Same as above
IMPORTANT NOTE: After you introduce the file into the repository, it is necessary that everyone who still has old CRLF files does step 3 and 4 to update their working directory as just checking out the commit doesn't affect already existing files.
setting core.autocrlf
to true
or input
overrides core.eol
https://www.git-scm.com/docs/git-config#Documentation/git-config.txt-coreautocrlf
core.autocrlf = input
is the preferred value on unix systems.
https://stackoverflow.com/a/41282375/985454
https://stackoverflow.com/a/4425433/985454
Reinstall git for windows with third option (as in the screenshot in Q)
Checkout as is - Commit as is (
core.autocrlf = false
)