avfrolov
avfrolov

Reputation: 526

How can I disable diff in line separators in IntelliJ IDEA?

I'm using Intellij IDEA 14 on Windows and Git as VCS on Unix server. The line separator in Windows is CLRF (\r\n) and LF (\n) in Unix. In Git, I'm using config --global core.autocrlf input. This will translate all CRLF's to LF's upon commit.

When I'm using "Reformat code" option on well-formatted file, IDEA marks files as changed and shows diff in line separators only.

Right mouse button on changed file -> Git -> Compare with Latest Repository Version

How can I disable that in IDEA?

Upvotes: 49

Views: 76838

Answers (8)

leonidas12515
leonidas12515

Reputation: 21

  1. To get to the settings (just hit Ctrl + Alt + S), go to Editor > Code Style > General. Next, choose the option you want for the line separator.
  2. In Project View, click on the directory (probably your whole project) to select it. Then, go to File > File Properties > Line Separators and choose the line separator you picked in Settings. Be aware that if you have a lot of files, your IDE might take a minute or two to process. No big deal, just wait.
  3. After that, go to the commit view (Alt + 0). Select all files and do a rollback. This will roll back all changes but keep the line separator settings.

Upvotes: 2

Svetlana Kashina
Svetlana Kashina

Reputation: 1

You can use System.lineSeparator() in your strings. It hepled me as my code had to be checked on a Linux server and my local computer uses Windows, so the line separators for these two are different.

Upvotes: -3

Evgene
Evgene

Reputation: 606

select folder -> File -> File Properties -> Line Separator -> LF

All files will be markd as changed.

Make regular commit with line separator changes ounly. It will fail but changed marks will disappear.

New files will inherit folder property.

Upvotes: 7

Roman Gorbatenko
Roman Gorbatenko

Reputation: 149

If you came to this thread like me seeking an answer as to why your unit test (JUnit) fails on comparing generated JSON (or any other structure that contains line separators) with one written by hand, you should replace \n by \r\n (for Windows) in your string. The instructions given above don't work for this case.

Upvotes: 7

Alex
Alex

Reputation: 37

Create parser.py in the same dir. Change the name and run. Enjoy))

with open('./file_to_fix.py', 'r') as f:
    a = f.read()

with open('./file_to_fix.py', 'w') as f:
    # for i in a.split('\r\n'):
    #     f.write(i)
    aa = a.replace('\r\n', '\n')
    f.write(aa)

Upvotes: -2

Hubert Schumacher
Hubert Schumacher

Reputation: 1985

In Intellij 17.3, you can select in the "Compare by" combobox in the compare window whether you want to compare 'Binary content' or 'Text'. In the second case CRLF and LF are not shown as "different".

Upvotes: 0

dsaydon
dsaydon

Reputation: 4769

I'm also developing on windows and Because our servers are powered by Linux and all the code has to base on Linux I have preferred to change all my files to LF instead of CRLF.

from git command line:

git config --global core.autocrlf false

i'm working with intellij idea so it's quite easy:

1) File --> settings --> editor --> code style: (for any new file will be created)

a. Scheme : default

b. Line separator: unix and os x (\n)

2) mark the root of the project --> file --> line separator --> LF unix and os x (\n) (for exist files)

Remark: you can also use apps like dos2unix.exe or some other scripts.

than I did using my command line: (you can do this also from the idea)

git commit -m "bla bla"
git add .
git push origin master

since then, I didn't got those warnings

Upvotes: 26

Peter Lawrey
Peter Lawrey

Reputation: 533870

In the bottom right of your window, change [CRLF] to [LF]

Upvotes: 40

Related Questions