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

点点圈 提交于 2019-12-11 13:44:10

问题


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.


回答1:


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




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/31051346/is-there-any-way-to-compare-two-files-in-git-without-their-formatting-changes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!