2017-01-23 72 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

相關問題