Why does IntelliJ change line separators on save from CRLF to LF

Viewed 7275
  • I do not have IntelliJ's "Save Actions" plugin installed.
  • git config core.autocrlf => true
  • git config core.safecrlf => true
  • Running Windows 10 for my sins
  • The corresponding .gitattributes file has * text=auto

I have a git repo checked out onto a Windows box. IntelliJ initially shows the files are initially CRLF line-separators (correct as I'm running Windows).

  • When I save an existing (Java) file in IntelliJ, the line-separators are CHANGED TO LF.
  • When I save the file via Notepad++ or VSCode, the line-separators are NOT CHANGED.

This means that when I do a git add it fails with fatal: LF would be replaced by CRLF in <file>.

FWIW

  • Checkout git repo via Windows Console, or Git Bash console makes no difference
  • At some point in the past I cloned via Ubuntu on WSL, but I've since done a clean clone into a new folder.

Are there any IntelliJ settings to stop it changing CRLF -> LF?

The workaround is to use --ignore-errors, e.g. git add --ignore-errors <file> but that's annoying.

1 Answers

IntelliJ IDEA honors .editorconfig configuration by default which overrides IDE formatting settings.

You can either disable this feature or remove this file from the project.

Related