How do I move a commit between branches in Git?

回眸只為那壹抹淺笑 提交于 2019-12-02 20:06:33

You can use git cherry-pick to grab C, and put it on Y. Assuming Y exists as the tip a branch called branch-Y:

$ git checkout branch-Y
$ git cherry-pick C

So now C is on top of Y. But D and E also still contain C (cherry picking doesn't move a commit, it just makes a copy of it). You'll have to rebase D and E on top of B. Assuming E is the tip of branch-E and B is branch-B, you can:

$ git checkout branch-E
$ git rebase --interactive branch-B

This will open up an interactive rebase session. Just remove commit C entirely, and leave D and E intact. You'll then have D and E rebased on top of B without C.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!