在本地合并三个github分支

时间:2015-01-08 12:45:47

标签: git github merge git-merge git-bash

目前我有一个场景,我想在本地将两个分支合并到第三个分支。所以场景是。仅供参考我是github的菜鸟。

  1. 主人 - > Epic_1
  2. 主人 - > Epic_2
  3. 现在我想首先将Epic_1分支合并到Master,然后在合并的Epic_1和Master之上将Epic_2分支合并到master。我不知道该搜索什么来获得正确的答案,所以添加这个问题。 重要 - 我希望所有这些只在本地完成,没有任何东西应该转到远程分支。

    谢谢, 射线

2 个答案:

答案 0 :(得分:3)

git checkout master   # go to master since that’s your target branch
git merge Epic_1      # merge in the first branch
git merge Epic_2      # merge in the second branch

这会给你一个看起来像这样的结果:

            (old) master      master (after merges)
                    ↓           ↓
* -- * -- * -- * -- * -- M1 -- M2
                       /      /
* -- * -- * -- * -- * -      /
                    ↑       /
                  Epic_1   /
                          /
* -- * -- * -- * -- * -- *
                         ↑
                       Epic_2

与Git中的所有内容一样,这仅在本地发生,因此任何遥控器上的任何内容都不会受到影响。当然,您可以推动主分支在遥控器上更新它。

答案 1 :(得分:0)

你只是

git fetch # in case these branches are from the remote and to be up-to-date

git checkout master

git merge branch_1

git merge branch_2

您现在可以

git status

git log

看到主人的状态。它将是本地的,除非/直到你明确地将master推送到远程(在你的情况下可能是origin)。

如果有合并提交,你需要解决它们,但是你会收到一条相应的消息,表明这是一个单独的问题。

还有很多关于合并和变基的选项以及快速转发等相关主题,但这超出了这个问题的范围。

相关问题