首页 > 解决方案 > 如何查看一个分支的更改是否已经在另一个分支中完成?

问题描述

我想知道我在 BranchA 上的所有代码更改是否已经在 BranchB 上应用,无论提交 ID 是否相同或 BranchB 是否有大量额外更改

那可能吗?

例子:

 Branch A :  Commit 111... -> Add line 23
             Commit 222... -> Add line 24
 Branch B:   Commit 333... -> Add line 23
             Commit 444... -> Add line 24
             Commit 555... -> Remove line 24
             Commit 666... -> Add line 25
             Commit 777... -> Add line 26
What I basically would like to know is whether the two changes from Branch A are already applied by other commits on Branch B.
In this case, the output I would like to see is:

  - Add line 24

Why? Because this is the only change from Branch A not matching latest state of Branch B. I want to discard extra staff exclusive in Branch B (commits 666 and 777). I also want to consider latest state of Branch B, so even Branch B added at some point line 24, the latest state is removed, so that is the only differing change in regards to Branch A

当使用比较和差异时,我通常会看到来自 B 分支的所有额外员工,我不感兴趣,因为我只想知道分支 A 的上下文中的差异

标签: gitbranchgit-log

解决方案


如果您合并所有更改,则可以这样做git log BranchB..BranchA(即“给我所有在 A 中而不在 B 中的提交”)。如果这不返回任何内容,则应用所有 A 更改。

如果您使用变基或以完全不同的方式实施更改,则无法检查这一点,因为您的更改可能在以后被更改或完全覆盖。您可以尝试 grep 一些相关行或构建软件,看看它是否具有您想要的功能,但没有通用的方法。


推荐阅读