Move multiple non-consecutive commits to different branch

谁说胖子不能爱 提交于 2019-12-25 06:50:47

问题


I've got two branches which shouldn't be directly merged together (yet). However, I need to move two different non-consecutive commits from one branch to the other. I currently have:

top-branch:
A-B-C-D

bottom-branch:
X-Y

And I want to get:

top-branch:
A-C

bottom-branch:
X-Y-B-D

回答1:


Assuming that you start from a situation similar to this one:

> git log --oneline --graph --all --decorate=short
* e08a53c (HEAD, bottom-branch) Y
* b659a43 X
| * 88612b2 (top-branch) D
| * 8b37e26 C
| * afe4ffd B
| * 5bc157c A
|/
* e3c7a2d other commit

I would start from branch bottom-branch cherry-picking the two commits you need

git cherry-pick afe4ffd

Then go back to top-branch and interactive rebase to remove the two commits you do not need

git rebase -i HEAD~4


来源:https://stackoverflow.com/questions/36493916/move-multiple-non-consecutive-commits-to-different-branch

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