2017-01-23 151 views

回答

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 

现在,通过revertrebase删除branchB的两次提交。回复更好,因为它不会改变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 
+0

做我需要做任何事情后摘樱桃(推代码到服务器)? – lee

+0

是的,您需要将最新的代码推送到远程。 –

+1

@lee在分支B上恢复这两个提交可能会更好,而不是使用交互式底图('rebase -i')将其移除。如果有人(或许多人)已经将您之前推送到分支B的更改撤回,那么当您(强制)推送更新的分支时,您将为他们重写历史记录。这会让他们头疼,并且反对git礼仪。 – mattliu

相关问题