简体   繁体   English

git多分支差异?

[英]Multi-branch diff with git?

Is there an easy way to get the diff between multiple (more than two) branches with git? 有没有一种简单的方法来使用git获得多个(两个以上)分支之间的差异? (Something like an "octopus diff"?) (有点像“章鱼差异”吗?)

The situation is that there is a branch (call it branch A) which is the result of a merge of multiple other branches (call them B and C) along with other modifications. 情况是存在一个分支(称为分支A),这是多个其他分支(称为B和C)与其他修改合并而成的结果。 (Branch A diverged from branch B, had a number of local modifications, then branch C was merged in, followed by more local modifications, then even more local modifications and re-merging to include updates on the B and C branches.) (分支A与分支B分开,进行了许多本地修改,然后合并了分支C,接着进行了更多本地修改,然后进行了更多本地修改,然后重新合并以包括B和C分支上的更新。)

What I'd like to do is see all local changes unique to branch A - that is, see what changes have been made to branch A that aren't on either branch B or branch C. 我想做的是查看分支A特有的所有本地更改-也就是说,查看分支B或分支C上没有对分支A进行的更改。

Make a branch "bPlusC" off of B, and then merge "C". 从B创建分支“ bPlusC”,然后合并“ C”。 Diff that with "A". 用“ A”表示。

git checkout -b bPlusC B
git merge --no-ff C
git checkout A
git diff bPlusC..HEAD

EDIT: Based on RM's comment: 编辑:基于RM的评论:

If B or C have commits that are not in A use this: 如果B或C的提交不在A中,请使用以下命令:

git checkout -b bPlusC $(git merge-base A B)
git merge --no-ff $(git merge-base A C)
git checkout A
git diff bPlusC..HEAD

(Posting an option which doesn't completely answer my question, but which I puzzled out during my research.) (发布一个选项并不能完全回答我的问题,但是我在研究过程中感到困惑。)

One possibility is to use the -p (patch) option of git log , which can take multiple branch labels for both inclusion and exclusion: 一种可能性是使用git log的-p(补丁)选项,该选项可以为包含和排除使用多个分支标签:

git log -p branch_A ^branch_B ^branch_C

This doesn't give a single summary of changes like git diff would, though, instead giving the separate changes for each commit included in branch A but not in branches B or C. 但是,这没有像git diff那样给出更改的摘要,而是给出了分支A中包含的每个提交的单独更改,但分支B或C中没有提供。

While less than ideal for getting an overall picture of the changes introduced by branch A, this commit-by-commit summary might be more useful when you're trying to cherry-pick changes from branch A. 虽然对于获取分支A所引入的更改的总体情况不太理想,但是当您尝试从分支A挑选变更时,此逐次提交摘要可能会更有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM