Is there any way to compare two files in Git without their formatting changes?

4.4k views Asked by At

I have committed some code with some format but the origin has some other format. The reviewer is asking me to revert all my changes and I am searching for some UI tool or some way in Git to remove formatting and give the actual result.

3

There are 3 answers

2
edi9999 On BEST ANSWER

I think you might have a look at git diff, in particular the two following options:

-b, --ignore-space-change
   Ignore changes in amount of whitespace. This ignores whitespace at line end, and considers all other sequences of one or more whitespace characters to be equivalent.

-w, --ignore-all-space
   Ignore whitespace when comparing lines. This ignores differences even if one line has whitespace where the other line has none.

So running git diff --ignore-all-space

However, if what you define by formatting is not just whitespace, I guess you have to do it by hand

0
unknownerror On

If you use intellij, consider using the version control tool provided by it.

The below link details on how to get a diff between two branches. https://stackoverflow.com/a/49642681/2960555

for a single file diff, You can right click on file -> git -> compare.

A new window will gets opened. select ignore options in that.

0
pramod bhargava On

Kdiff3 is the tool i needed to get my work done This is a GUI tool for UNIX systems which can compare two file remove conflicts check for changes