Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git and IntelliJ lines separator issue

I am working in IntelliJ 15.0.3 and using Git through Git Bash (to commit and push changes). When I fetch file from remote git repository it contains different line separators (mixed mode or how it's called). I mean that some lines ends with CRLF and some lines ends with LF (the same file).

When I make change in IDEA - file is automatically saved and all line separators are reduced (changed) to IDEA default line separator (LF for me).

And git treats these changes as changes to the file, as a result I commit file with a lot of changes like these:

- some line
+ some line

Because some line [CRLF] was changed to some line [LF].

How to configure Git to ignore this or how to configure IntelliJ IDEA to leave file in this mix-mode? I don't want to commit changes when there are no changes.

like image 938
ikos23 Avatar asked Feb 19 '16 10:02

ikos23


People also ask

How do I change the line separator in IntelliJ?

Change line separators for a file or directoryFrom the main menu, select File | File Properties | Line Separators, and then select a line ending style from the list.

What is Crlf line separators?

CR and LF are control characters or bytecode that can be used to mark a line break in a text file. CR = Carriage Return ( \r , 0x0D in hexadecimal, 13 in decimal) — moves the cursor to the beginning of the line without advancing to the next line.

How do I change from CRLF to LF in Git?

You can set the mode to use by adding an additional parameter of true or false to the above command line. If core. autocrlf is set to true, that means that any time you add a file to the Git repository that Git thinks is a text file, it will turn all CRLF line endings to just LF before it stores it in the commit.


2 Answers

While installing git, we will have option to set the checkout as-is and commit as-is.

If that is not set, we can do with the git config.

Following command helps you in doing so.

git config --global core.autocrlf true

As per documentation:

    Git can handle this by auto-converting CRLF line endings into LF when you
 add a file to the index, and vice versa when it checks out code onto your 
filesystem. You can turn on this functionality with the core.autocrlf setting. 
If you’re on a Windows machine, set it to true – this converts LF endings into 
like image 175
Vinay Veluri Avatar answered Oct 27 '22 22:10

Vinay Veluri


IDEA delegates changes resolution to git.

So you would have to either force desired line breaks in IDEA or to force desired line breaks in git.

In my case autocrlf true was already present on my PC but the working copy was initially copied from collegue's share where it had been checked out with another setting.

A clean checkout would resolve the problem but I had some files already changed and wanted to preserve them. This can be worked around by resetting git index for the whole project or just desired subdirectory.

like image 25
Vadzim Avatar answered Oct 27 '22 22:10

Vadzim