Git / source树将分支B的特定提交移动到分支A

时间:2017-01-23 03:27:05

标签: git github terminal sourcetree

发育时我发生了意外。我有两个提交需要在分支A但我推到分支B.所以现在,我想将这些提交移动到分支A然后从分支B中删除它们。请查看图像以获取详细信息:

enter image description here

1 个答案:

答案 0 :(得分:2)

首先,转到branchAcherry-pick这两个要提交的提交。

$ git checkout branchA
$ git cherry-pick <commit1>       # commit1 = 0a18e0f   
$ git cherry-pick <commit2>       # commit2 = e604ce4

$ git push origin HEAD            # push to remote

现在从branchBrevert移除rebase的两次提交。 Revert是首选,因为它不会改变git历史记录。

<强>恢复

$ git checkout branchB
$ git revert <commit1>
$ git revert <commit2>
$ git push origin HEAD

<强>调整基线:

$ git checkout branchB
$ git rebase -i efb2443         # go back to the commit before the two commmits you want to remove

Now comment out (adding `#` before the commit hash) the two commits you want to remove.

$ git push -f origin HEAD       # you need to force(-f) push as history is changed here by rebasing