将一个git分支与一个额外的提交复制到另一个后面

时间:2013-06-14 19:22:47

标签: git git-branch git-merge git-commit

我有以下git结构(Numbers表示提交):

  _ 1 _ 2 _ 3 _ 4  (Branch mainline)
_|
 |_ 1 _ 2 _ 3 _ 4 _ 5 (Branch Test)

因此,Test有一个额外的提交而不是主线。我基本上需要将该提交复制到主线。我该怎么做?

所以我的最终状态应该是:

  _ 1 _ 2 _ 3 _ 4 _ 5 (Branch mainline)
_|
 |_ 1 _ 2 _ 3 _ 4 _ 5 (Branch Test)

1 个答案:

答案 0 :(得分:0)

  1. 一个选项:

    git checkout mainline
    

    然后是任何一个:

    git merge test
    git rebase test
    git reset --hard test
    git cherry-pick test  #probably not really recommended
    
  2. 另一种选择:

    git branch -D mainline
    git checkout -b mainline test
    
  3. 我相信还有更多。