有什么方法可以在不更改格式的情况下比较 Git 中的两个文件?

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

我已经提交了一些具有某种格式的代码,但源代码有一些其他格式。审阅者要求我恢复所有更改,我正在寻找一些 UI 工具或 Git 中的某种方式来删除格式并给出实际结果。

我想你可以看看 git diff,特别是以下两个选项:

-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.

所以运行git diff --ignore-all-space

但是,如果您通过格式化定义的不仅仅是空格,我想您必须手动完成

Kdiff3 是我完成工作所需的工具 这是一个用于 UNIX 系统的 GUI 工具,可以比较两个文件删除冲突检查更改

如果您使用intellij,请考虑使用它提供的version control工具。

下面的 link 详细介绍了如何获取两个分支之间的差异。

对于单个文件差异,您可以右键单击文件 -> git -> 比较。

一个新的 window 将被打开。 select 忽略其中的选项。