如何查看树冲突("deleted by us" 或 "deleted by them")中的变化?

How do I see the changes in a tree conflict ("deleted by us" or "deleted by them")?

在 git 中合并或变基两个分支时,一个文件已被删除但另一个被修改,git 会产生冲突。 git status 将文件显示为 "deleted by us" 或 "deleted by them".

我发现了很多关于如何解决冲突的问题,包括:

然而,大多数答案假设您已经确切知道冲突是什么,只需要告诉 git 保留或删除文件。

如何找出删除的文件版本中发生了什么变化git 只是将整个文件留在工作副本中,不标记任何更改。

例如:

如果"deleted by us":

git diff <your-branch>...<branch-you're-merging-to> /path/to/file

如果"deleted by them":

git diff <branch-you're-merging-to>...<your-branch> /path/to/file

来自 git-diff 手册页:

git diff [<options>] <commit>...<commit> [--] [<path>...]

This form is to view the changes on the branch containing and up to the second <commit>, starting at a common ancestor of both <commit>. "git diff A...B" is equivalent to "git diff $(git merge-base A B) B". You can omit any one of <commit>, which has the same effect as using HEAD instead.

这只会显示在未删除文件的分支中所做的更改,即如果删除文件的分支首先对其进行了任何更改,则这些更改不会反映在差异中。

如果您要变基而不是合并,那么 "deleted by us" / "deleted by them" 消息将相反,因此请使用其他命令。