我想知道我对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上下文中的差异
答案 0 :(得分:3)
如果您合并所有更改,则可以使用git log BranchB..BranchA
(即“给我所有在A中而不在B中的所有提交”)来完成。如果未返回任何内容,则将应用所有A更改。
如果您使用rebase或以完全不同的方式实现更改,则无法检查此情况,因为您的更改以后可能会被更改或完全覆盖。您可以尝试grep一些相关的代码或构建软件,看看它是否具有所需的功能,但是没有通用的方法。
答案 1 :(得分:3)
您也可以:
git branch --contains BranchA
列出具有所有BranchA提交的所有分支。如果您在列表中找到BranchB,那就很好。
如果有许多分支,请通过管道传递给grep:
git branch --contains BranchA | grep BranchB
评论后编辑:
如果您必须检测更改而不论它们属于什么提交,例如,当您以kostix suggests为基础进行重新整理或挑选某些工作时,可以执行以下操作:
git log --cherry BranchB..BranchA
但是再说一次,尽管更改的检测将在代码级别发生,但无论提交哈希如何,默认情况下,输出本身都将作为提交给出。要查看这些提交中实际的代码更改,可以使用-p
选项,并将其存储在文件中:
git log -p --cherry BranchB..BranchA > output.txt