Git 比较两个分支与第三个分支的关系

标签 git github gitlab git-diff

使用 github/gitlab,在许多情况下使用功能分支, pull 请求在等待审查时会过时,需要在一段时间后重新基于新的目标分支(master)。

这有时会产生需要解决的冲突。

在 rebase 之后,我想比较与目标分支相关的旧分支和新分支,以验证在解决冲突时没有发生错误。这意味着我想验证在 merge 新版本的 PR 后哪些行会发生变化。

所以基本上我想比较 git diff branch origin/mastergit 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/masterorigin/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/

相关文章:

github - 我可以在 GitHub gui 中搜索一系列标签中的提交吗?

docker - Jenkins & GitLab & Docker 集成失败

git - 在git中找到文件的第一次提交

android - 从 git 项目添加 gradle 依赖

git - 如何修复 GIT 存储库中的 CRLF 以避免 merge 冲突

git - RPC失败;结果=28,HTTP 代码=0

node.js - 在 GitLab CI 中为 Node.js 应用程序构建 Docker 镜像

ubuntu - ssh/known_hosts : No such file or directory

git - 为什么公共(public)目录中的文件不会被忽略?

git - 无法使用 VS 2015 和 GIT 将文件添加到源代码管理