关于git:如何将多个分支合并到master中?


How do I merge multiple branches into master?

1
2
3
4
5
6
7
8
9
        C---D  =>b1
      /    
     /  E---F  =>b2
     | /  
  A--B =======> master
     | \
     \  G---H  =>b3
      \
       I---J   =>b4

我想把b1b2b3b4合并成master,可以一次合并吗?

比如:

1
2
git checkout master
git merge b1 b2 b3 b4


git的merge命令支持多种合并策略。有两种策略可以一次合并两个以上的分支。

另请参阅此问题,了解对每个问题的不太正式的描述。

章鱼

This resolves cases with more than two
heads, but refuses to do a complex merge that needs manual resolution.
It is primarily meant to be used for bundling topic branch heads
together. This is the default merge strategy when pulling or merging
more than one branch.

最后一句话意味着,如果你使用git merge branch1 branch2 ...,它将使用章鱼策略。

我们的

This resolves any number of heads, but the resulting tree of the merge is always that of the current branch head, effectively ignoring
all changes from all other branches. It is meant to be used to
supersede old development history of side branches.

有关用例示例,请参见此问题。


Git有一个名为Octupus的合并策略,它可以合并多个分支,只要不存在复杂的冲突。执行此操作的命令与您建议的git merge b1 b2完全相同。