13

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:

My Git Settings in PhpStorm

Chris Bornhoft
  • 4,195
  • 4
  • 37
  • 55
Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291

3 Answers3

16

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.

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
7

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I 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 Jan 01 '15 at 12:10
  • It 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 example `git -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.` – Marcin Nabiałek Jan 06 '15 at 21:51
  • @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. – VonC Jan 06 '15 at 21:54
  • So what should I do? I've edited my question and added configs I found and screen from PhpStorm – Marcin Nabiałek Jan 06 '15 at 22:11
  • @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. – VonC Jan 06 '15 at 22:20
  • Have 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 – Marcin Nabiałek Jan 07 '15 at 19:47
  • @MarcinNabiałek no additional clue for now. – VonC Jan 07 '15 at 19:48
  • I 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 using `crlf` so it is just continuing with that." But now I see it has just changed a file that was all linux style into using `crlf`. I am using PhpStorm 2016.1. And I have been struggling with these line ending inconsistencies for almost a year now. – Buttle Butkus May 08 '16 at 01:48
  • This 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 after `input`, to be honest, but I just wanted to be sure). – jurchiks Oct 22 '19 at 08:56
  • @jurchiks Maybe PHPStorm does not respect the config `core.autocrlf`? But regarding Git, a `core.autocrlf` set to `false` means: touch nothing (unless you gave `.gitattributes` directives in place of course) – VonC Oct 22 '19 at 09:01
  • @VonC it isn't PHPStorm; changing this to `input` solved the issue. I know `false` should do nothing, but maybe Git for Windows thinks differently or something like that. – jurchiks Oct 22 '19 at 15:40
  • @jurchiks Can you check a `git config --show-origin -l` done from within your repository folder? Maybe there were multiple `core.autocrlf` defined? – VonC Oct 22 '19 at 15:44
  • @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 also `file:C:/Users/{myusername}/.gitconfig core.autocrlf=input`, which overrides the system one and it works perfectly. – jurchiks Oct 23 '19 at 10:39
3

git config --global core.autocrlf input will ensure LF only for all git projects.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73