Alexander
Alexander

Reputation: 73

Ignore new lines and brackets style with diff

Is there anyway to ignore style changes made by the Eclipse code formatting (Eg new lines, bracket style, etc), right now it just create a bunch of unnecessary stuff in my patch file.

Using the command diff -ur original modified > source.diff

Update: Sample input and desired output

The original code looks like:

   private void sampleFunction()
   {
        // Code
   }

But after i've used Eclipse, it looks like:

   private void sampleFunction() {
        // Code
   }

And when using diff, it will include this. Is there any way to make it ignore this ?

Upvotes: 3

Views: 701

Answers (1)

PowerStat
PowerStat

Reputation: 3821

There is no way to ignore style changes by any diff program, because diff never has semantic information about the files you compare!

The correct solution would be to configure the eclipse formatter (you could have more than one format!) so that it results in (nearly) the same style as the original one.

But possibly it is more simple to fix your problem by switching off eclipses automatic formatting on save action:

enter image description here

This should leave the formatting untouched as long as you are not doing a formatting manually (by context menu/source/formatting) or by using ctrl+shift+f.

Upvotes: 1

Related Questions