如何查看分支中的更改是否已在另一个分支中完成?

问题描述 投票:2回答:2

我想知道我在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的背景差异

git branch git-log
2个回答
3
投票

你也可以这样做:

git branch --contains BranchA

列出所有Branch的提交的所有分支。如果你在列表中找到你的分支,那你很好。

在许多分支的情况下,管道grep:

git branch --contains BranchA | grep BranchB

评论后编辑:

如果您必须检测更改,无论它们属于哪些提交,例如当您重新定位或挑选某些工作时,如kostix suggests,您可以执行以下操作:

git log --cherry BranchB..BranchA

但话又说回来,虽然检测更改将在代码级别进行,但无论提交哈希值如何,输出本身都将默认为提交。要查看这些提交中的实际代码更改,您可以使用-p选项,并可能将其存储在文件中:

git log -p --cherry BranchB..BranchA > output.txt

3
投票

如果你合并了所有的更改,可以使用git log BranchB..BranchA完成(即“给我所有在A中但不在B中的提交”)。如果不返回任何内容,则应用所有A更改。

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

© www.soinside.com 2019 - 2024. All rights reserved.