将多个非连续的提交移动到不同的分支 [英] Move multiple non-consecutive commits to different branch

查看:80
本文介绍了将多个非连续的提交移动到不同的分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个不应直接合并在一起的分支(尚未).但是,我需要将两个不同的非连续提交从一个分支移动到另一个分支.我目前有:

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

我想得到:

top-branch:
A-C

bottom-branch:
X-Y-B-D

推荐答案

假设您是从与此类似的情况开始的:

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

我将从分支bottom-branch开始,挑选您需要的两个提交

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

git cherry-pick afe4ffd

然后返回top-branch并进行交互式变基,以删除您不需要的两个提交

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

git rebase -i HEAD~4

这篇关于将多个非连续的提交移动到不同的分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆