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

Git/source tree move specific commits at branch B to branch A

我在开发的时候出了意外。我有两个提交需要在分支 A 但我推送到分支 B。所以现在,我想将这些提交移动到分支 A,然后将它们从分支 B 中删除。请查看图片了解详情:

首先,转到 branchAcherry-pick 您要在此处选择的两个提交。

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

$ git push origin HEAD            # push to remote

现在从 branchB 中删除 revertrebase 的两个提交。还原是可取的,因为它不会改变 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