Something keeps changing file newlines to CRLF

I changed the default in my PHPStorm at the IDE level to "Unix and MacOS (\n)" (LF right?),

and when I click the CRLF button at the bottom right of the file to change it to LF,

it saves and lets me commit that way (I'm assuming), but then the next day or so I come in and when I re-open the file it seems to randomly be CRLF again, screwing up my ability to stage "hunks" in git SourceTree (I get an error about patch will not apply), nevermind that another developer got the "wall-of-pink" issue once (look it up) because our previous developer used Windows and they didn't do `git config --global core.autocrlf true` as I do (so the file saved with CRLF even though we host on Linux and all now use Macs).

So... why does it keep switching to CRLF? Is it PHPStorm, or the Mac, or the file, or git, or SourceTree? I can't tell.

What's going on or what am I missing?

4

Same problem in intellij. And it happens of 'Frame deactivation'.

0

Frame deactivation saves the file & applies line ending settings.We need more information about the problem, e.g. your "Line separator" setting at File | Settings | Editor | Code Style, is it a locally stored project, are any other processes & users accessing this file, does it occur after a commit/save/etc?

0

Hi Dmitry. In my case I think I found the problem. Problem happens when EditorConfig  support enabled.

Posted it as bug https://youtrack.jetbrains.com/issue/IDEA-225911

Here by the way in phpstorm it also enabled according to first screen.

 

4

My line setting is in the original post and screenshot... "Unix and MacOS (\n)".

It stopped changing it back to CRLF a while ago though, not sure why.

May have been doing it when switching branches, but I already configured the recommended git line-ending configurations for converting to Linux newline on commit and the my OS when I checkout.

Honestly with PHPStorm, I'm not sure what the git config should be for line endings (in each repo and server) if our team is coding with Macs but eventually someone may code in Windows or Linux. We run our dev tests locally on Mac (which could be Windows or Linux eventually) and then QA and Prod run on Linux.

0

Mine just stopped doing it... not sure what caused it.

0

This is very much still happening. 

8

I'm having the same problem in PyCharm 2025.2

0

I have the same issue on InteliJ 2025.2.1 with Java (on Windows) 

0

Moshe Danweil68 Hi, could you please share the below info for investigating your issue further:

Please run git config core.autocrlf in this project's Terminal and share the output.

Also, after you encounter this issue again, could you please right-click the affected file, choose Local History → Show History, and locate the entry where the file was converted to CRLF format? What is the name of that history entry? Does it appear as “Changed Line Separators from CR to CRLF”, or does it have a different name, such as “External Change”?

If you use EditorConfig, make sure your .editorconfig file is configured with the correct end_of_line setting.

0

Lejia Chen 

Hi, sorry for taking so long to reply.

Running  git config core.autocrlf
printed
true

I am using a Windows computer.

As for finding the changes in the local history, I'd given up fighting this a while back, so I can't find the changes. I'm changing files back to LF now, and will try to keep an eye out to see if/when they change back.

Thinking about it further, I wonder if AI Assistant/Junie is to blame

0

Update:
It's not the AI. It happened in a history entry just labeled “Change”, that was made by the IDE optimizing imports on a commit. In fact, it was the commit I made for changing the line endings back to LF. Normally, when that's the only change in a commit, the commit fails, which I expected to happen here. But apparently the imports were not in alphabetical order somehow, so the automatic optimization kicked in, swapping the order of the imports and changing the line endings to CRLF

0

Moshe Thanks for the updates. What option do you use in `Settings | Languages & Frameworks | PHP | Quality Tools | External Formatters`?

0

I have also autocrlf = true

git config core.autocrlf
true

I'm on Windows, editing JAVA files. My endlines should be CRLF and InteliJ, sometimes (not always) changes my file into a LF files.

Unfortunately I could not find any change in the local history concerning a LF or CRLF change

0

Danweil68 Can you please try to change your file to CRLF and after you see this issue again, and check any changes in local history? There should be an entry after reproducing this issue.

By default, Local History is configured to store revisions for the last 5 working days (that is, days when the file was modified). So if you saw this issue and the local history might be already cleared if the line endings were changed before 5 days.

You can configure the option here https://www.jetbrains.com/help/idea/local-history.html#local-history-retention to make the Local history longer.

 

AFAIK, the line ending issue can be caused by different rules configured in EditorConfig (if you use EditorConfig) or an external formatter. (there are some ways to use external formatter in IntelliJ)

 

 

0

Lejia Chen I don't have that option. I am using Pycharm, not PHPStorm. Under “Languages and Frameworks” there is no option for Python (or PHP):

Under the “Python” menu I see nothing about formatters:
 

0

@Moshe Sorry, the original reporter was using PhpStorm, so I misunderstood and thought you were using PhpStorm too.

Can you please share screenshots of `Settings | Tools | Black` and `File | Settings | Tools | Actions on Save` setting pages?

 

0

Lejia Chen 

Black is not installed:
 

 

Here's the Actions on Save:
 

0

Lejia Chen 

I just realized that the Ruff formatter (which I run automatically on commit using the pre-commit library) might be at least partially responsible. I've been using the default config, which has line-ending = "auto". I think this detects the first line ending used in the file though, which means that once I had converted the entire file to “LF” it shouldn't change it back by itself. Also, I'm not certain, but I think this problem was happening before I started using Ruff. So maybe it's not a factor at all, but I felt I should mention it just in case

Now I'm configuring it with line-ending = "lf"; if I keep seeing CRLF then we'll know that whatever is changing it happens after pre-commit runs

0

Update: I just saw this line in my Git console log:

warning: in the working copy of 'backend/src/violation_cache.py', LF will be replaced by CRLF the next time Git touches it

 

0

@Moshe Thanks for the updates.

It seems Git changed the encoding of your files.

Please try the suggestions here: https://stackoverflow.com/q/2517190

0

请先登录再写评论。