使用 github/gitlab,在许多情况下使用功能分支, pull 请求在等待审查时会过时,需要在一段时间后重新基于新的目标分支(master)。
这有时会产生需要解决的冲突。
在 rebase 之后,我想比较与目标分支相关的旧分支和新分支,以验证在解决冲突时没有发生错误。这意味着我想验证在 merge 新版本的 PR 后哪些行会发生变化。
所以基本上我想比较 git diff branch origin/master
和 git diff origin/branch origin/master
的结果 - diff 输出发生了什么变化github/gitlab新旧版本PR View
是否有执行此操作的命令?
最佳答案
是的,您可以使用 git-diff
的形式那takes multiple commits :
git diff <commit> <commit>… <commit>
来自documentation :
This form is to view the results of a merge commit. The first listed must be the merge itself; the remaining two or more commits should be its parents.
在您的情况下,您想要比较 rebase branch
之间的 merge 提交和 origin/master
与旧 origin/branch
之间的 merge 提交和 origin/master
;然后比较变成:
git diff branch origin/master origin/branch
哪里branch
是“merge 提交”和origin/master
和 origin/branch
是它的“ parent ”。
如果发生冲突,Git 将生成以下差异:
- line in origin/master (the first "parent" commit)
- line in origin/branch (the second "parent" commit)
+ line in branch (the merge commit)
关于Git 比较两个分支与第三个分支的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65086264/