问题
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