0

I made changes to a few lines of code in a certain class and each time I try to commit them, GitKraken claims that I'm attempting to commit the whole class. Every 1000+ lines of it.

I think this is some sort of automated code styling done in IntelliJ IDEA. I can't see the actual change anywhere but it has to be this.

Is there a setting to prevent IDEA from doing such stylings automatically to classes?

EDIT 1 - More info on the problem:

This problem only occurs in this one particular class. My colleague checked his code styling settings in his IDEA and they are identical to mine.

EDIT 2 - More info on the problem:

In Notepad++ when "showing every character" This particular class has only CR at the end of lines whereas all the other classes have CR LF.

No idea why is that. (pun not intended)

Any ideas how to fix this? (pun not intended)

EDIT 3 - Found the solution:

In notepad++ it is possible to replace even these non-visible, special characters so we added the LF to the end of each line and now it works. Not sure why these had disappeared in the first place.

Steve Waters
  • 3,348
  • 9
  • 54
  • 94

1 Answers1

1

There are few ways to achieve this. Personally, I use different code styles for my own and open source projects.

It means that when you know that you will be working on project with specific code convention it worth spending 20-30 minutes to configure proper Code Style.

You can configure them in Settings -> Code Style:

The most useful settings are:

  • Tabs and Indents (this is probably what you faced)
  • Blank lines
  • Imports

IntelliJ Code Style

You can find more about configuring code style in official documentation: Configuring Code Style

And also make sure that you are not ignoring whitespace while reviewing your code:

Intellij IDEA ignore whitespace

Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
  • Thanks for the great and elaborative answer but my colleague checked his code styling settings and they seem identical. Also, this problem occurs only in this one class. I'll update my question. – Steve Waters Jun 13 '17 at 07:46
  • @SteveWaters what is the difference between committed and raw file? In line breaks or whitespaces? – Andrii Abramov Jun 13 '17 at 07:56
  • I updated answer to elaborate on that. GitKraken shows that the commit is the WHOLE class on one line without linebreaks :) as in "package my.project;import my.project..." etc. the next line starting right from the semicolon on the same line. – Steve Waters Jun 13 '17 at 07:57
  • Still going to mark your answer as correct one since it elaborates perfectly on IDEA's styling settings. – Steve Waters Jun 13 '17 at 08:11