PhpStorm + GIT line endings changing from LF to CRLF
Solution 1
After tests it was obviously not PhpStorm issue but GIT config issue.
It seems that on Windows it's necessary to set:
git config --global core.autocrlf input
but also
git config --global core.eol lf
to make it work.
Solution 2
You can check if this Git setting can help:
git config --global core.autocrlf false
I usually recommend keeping core.autocrlf
to false (there are only a few reason to set it to true).
Check also if you have any .gitattributes
files with a core.eol
directive in it.
Solution 3
git config --global core.autocrlf input
will ensure LF only for all git projects.

Marcin Nabiałek
I'm a Cerified Laravel Developer & Zend Certified PHP Engineer experienced in making code reviews. If you need remote Laravel PHP developer or you are looking for someone to help you to keep high code quality, feel free to contact. Learn more about me at Marcin Nabiałek - Laravel PHP developer
Updated on June 04, 2022Comments
-
Marcin Nabiałek 7 months
I have set in my PhpStorm line endings to LF but when I commit to github, sometimes I see some of the files again appear with CRLF line ending (I work on Windows).
It happens with the same files I've edited and nobody edited them between my commits/pushes to repository. It's very irritating and I need to often change line endings to the same file. What could it be and how to fix it?
I also have checked option "Warn if CRLF line separators are about to be commited"
EDIT
My local git config is this:
[core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true hideDotFiles = dotGitOnly [remote "origin"] url = https://github.com/* fetch = +refs/heads/*:refs/remotes/origin/* [branch "develop"] remote = origin merge = refs/heads/develop
My global config is this:
[user] name = * email = * [core] autocrlf = false
My systemwide config is this:
[core] symlinks = false autocrlf = false [color] diff = auto status = auto branch = auto interactive = true [pack] packSizeLimit = 2g [help] format = html [http] sslCAinfo = /bin/curl-ca-bundle.crt [sendemail] smtpserver = /bin/msmtp.exe [diff "astextplain"] textconv = astextplain [rebase] autosquash = true
And my GIT settings in PhpStorm:
-
Marcin Nabiałek almost 8 yearsI used
git config --global --list
and it was indeed set to true so I changed it to false as you advised. In my.gitattributes
file I have only* text=auto
- nothing more. I will try to look it the problem still persists after this change -
Marcin Nabiałek almost 8 yearsIt seems it didn't help at all. I'm still getting CRLF in my files. I looked at Version controle console and I see there
git -c core.quotepath=false config core.autocrlf
and for examplegit -c core.quotepath=false add --ignore-errors -- tests/api/* warning: LF will be replaced by CRLF in tests/api/* The file will have its original line endings in your working directory.
-
VonC almost 8 years@MarcinNabiałek
git -c core.quotepath=false config core.autocrlf
would seem to force just for this session autocrlf to be set. Which would explain why the global config is ignored. -
Marcin Nabiałek almost 8 yearsSo what should I do? I've edited my question and added configs I found and screen from PhpStorm
-
VonC almost 8 years@MarcinNabiałek not sure, I'll check tomorrow, but if PhpStorm executes git commands in which it overrides the config (especially the core.autocrlf), that is not good.
-
Marcin Nabiałek almost 8 yearsHave you found any solution? I need to add, that today I've also created new composer project (no manual file creation) just to test the newest Laravel 5 (no GIT repo has been used here), and also all files that came from composer have CRLF line endings
-
VonC almost 8 years@MarcinNabiałek no additional clue for now.
-
Buttle Butkus over 6 yearsI have the PhpStorm setting under "Code Style" for "Line separator (for new files)" set to "Unix and OS X (\n)". So when I saw PhpStorm using
crlf
for existing files, I thought, "okay, those already were usingcrlf
so it is just continuing with that." But now I see it has just changed a file that was all linux style into usingcrlf
. I am using PhpStorm 2016.1. And I have been struggling with these line ending inconsistencies for almost a year now. -
jurchiks about 3 yearsThis does NOT, in fact, work. PHPStorm/GIT change the EOL to CRLF all the time when using this.
input
was the option that worked, along with a.gitattributes
file with*.php text eol=lf
(which may not do anything afterinput
, to be honest, but I just wanted to be sure). -
VonC about 3 years@jurchiks Maybe PHPStorm does not respect the config
core.autocrlf
? But regarding Git, acore.autocrlf
set tofalse
means: touch nothing (unless you gave.gitattributes
directives in place of course) -
jurchiks about 3 years@VonC it isn't PHPStorm; changing this to
input
solved the issue. I knowfalse
should do nothing, but maybe Git for Windows thinks differently or something like that. -
VonC about 3 years@jurchiks Can you check a
git config --show-origin -l
done from within your repository folder? Maybe there were multiplecore.autocrlf
defined? -
jurchiks about 3 years@VonC There weren't before I set it globally for my user;
file:"C:\\ProgramData/Git/config" core.autocrlf=false
was the system default. Now there's alsofile:C:/Users/{myusername}/.gitconfig core.autocrlf=input
, which overrides the system one and it works perfectly.