【发布时间】:2016-07-29 09:09:39
【问题描述】:
我有两个不应该直接合并在一起的分支(还)。但是,我需要将两个不同的非连续提交从一个分支移动到另一个分支。我目前有:
top-branch:
A-B-C-D
bottom-branch:
X-Y
我想得到:
top-branch:
A-C
bottom-branch:
X-Y-B-D
【问题讨论】:
标签: git git-branch git-rebase
我有两个不应该直接合并在一起的分支(还)。但是,我需要将两个不同的非连续提交从一个分支移动到另一个分支。我目前有:
top-branch:
A-B-C-D
bottom-branch:
X-Y
我想得到:
top-branch:
A-C
bottom-branch:
X-Y-B-D
【问题讨论】:
标签: git git-branch git-rebase
假设你从一个类似的情况开始:
> 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
我会从分支bottom-branchcherry-picking 你需要的两个提交开始
git cherry-pick afe4ffd
然后回到 top-branch 和交互式 rebase 以删除您不需要的两个提交
git rebase -i HEAD~4
【讨论】:
git cherry-pick