3

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 ?

Alexander
  • 73
  • 6
  • Please add sample input and your desired output for that sample input to your question. – Cyrus Apr 18 '17 at 18:53
  • 2
    Perhaps you can find a formatter that writes its result to stdout, and use spmething like `diff <(jformat orgcode.java) <(jformat newcode.java)` with jformat a tool like in http://stackoverflow.com/a/996672/3220113 – Walter A Apr 18 '17 at 21:10
  • @Munir `diff -w` will not ignore the change in the bracket style, because `diff` is line-oriented, and therefore does not treat newlines as "whitespace" for purposes of comparison. – Mike Holt Apr 18 '17 at 21:49

1 Answers1

1

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.

PowerStat
  • 3,757
  • 8
  • 32
  • 57