【发布时间】:2017-06-07 12:29:28
【问题描述】:
【问题讨论】:
标签: git github terminal sourcetree
【问题讨论】:
标签: git github terminal sourcetree
首先,转到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
现在从branchB 中删除revert 或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
【讨论】:
rebase -i) 删除它们。如果有人(或许多人)拉取了您之前推送到分支 B 的更改,那么当您(强制)推送更新的分支时,您将为他们重写历史记录。这会让他们头疼,而且是违反 git 礼仪的。