如何查看树冲突("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 - merge conflict when local is deleted but file exists in remote
- How do I fix a merge conflict due to removal of a file in a branch?
然而,大多数答案假设您已经确切知道冲突是什么,只需要告诉 git 保留或删除文件。
如何找出未删除的文件版本中发生了什么变化? git
只是将整个文件留在工作副本中,不标记任何更改。
例如:
- 在分支
develop
上,用户 A 更改文件 foo.x
- 在分支
feature
上,用户 B 重构代码,删除文件 foo.x
因为它的功能现在在其他文件中
- 用户 B 尝试将
develop
合并到 feature
中,并得到标记为 deleted by us
的冲突
- 用户 B 如何查看用户 A 更改了什么,以查看重构代码中是否需要更改?
如果"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" 消息将相反,因此请使用其他命令。
在 git 中合并或变基两个分支时,一个文件已被删除但另一个被修改,git 会产生冲突。 git status
将文件显示为 "deleted by us" 或 "deleted by them".
我发现了很多关于如何解决冲突的问题,包括:
- git - merge conflict when local is deleted but file exists in remote
- How do I fix a merge conflict due to removal of a file in a branch?
然而,大多数答案假设您已经确切知道冲突是什么,只需要告诉 git 保留或删除文件。
如何找出未删除的文件版本中发生了什么变化? git
只是将整个文件留在工作副本中,不标记任何更改。
例如:
- 在分支
develop
上,用户 A 更改文件foo.x
- 在分支
feature
上,用户 B 重构代码,删除文件foo.x
因为它的功能现在在其他文件中 - 用户 B 尝试将
develop
合并到feature
中,并得到标记为deleted by us
的冲突
- 用户 B 如何查看用户 A 更改了什么,以查看重构代码中是否需要更改?
如果"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" 消息将相反,因此请使用其他命令。