首先,进入branchA
并cherry-pick
你想要选择的两个提交。
$ git checkout branchA
$ git cherry-pick <commit1> # commit1 = 0a18e0f
$ git cherry-pick <commit2> # commit2 = e604ce4
$ git push origin HEAD # push to remote
现在通过使用 revert
或 rebase
从 branchB
中移除两个提交。优先考虑使用 revert,因为它不会改变 Git 历史记录。
Revert:
$ git checkout branchB
$ git revert <commit1>
$ git revert <commit2>
$ git push origin HEAD
Rebase:
$ 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
rebase -i
)将那两个提交从分支B中删除,不如还原它们。如果有人(或多人)已经拉取了你之前推送到分支B的更改,当你(强制)推送更新后的分支时,你将会改写他们的历史记录。这会给他们带来麻烦,并且违反了git的礼仪准则。 - mattliu