[英]Git/source tree move specific commits at branch B to branch A
I have an accident when develop.我在开发时发生了意外。 I have two commits which need at branch A but I pushed to branch B. So now, I want to move those commit to branch A and then remove them from branch B. Please view image for detail:
我有两个提交需要在分支 A,但我推送到分支 B。所以现在,我想将这些提交移动到分支 A,然后从分支 B 中删除它们。请查看图像以了解详细信息:
First, go to branchA
and cherry-pick
the two commits you want to pick here.首先,转到
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
Now remove the two commits from branchB
by revert
or rebase
.现在通过
revert
或rebase
从branchB
删除两个提交。 Revert is preferable because it does not change git history. 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.