git 提交到某分支,如何将某些提交移动到git中的另一个分支?

The situation:

master is at X;

quickfix1 is at X + 2 commits

Then I started working on quickfix2, but by accident took quickfix1 as the source branch to copy, not the master. Now quickfix2 is at X + 2 commits + 2 relevant commits.

Now I want to have a branch with quickfix2, but without the 2 commits that belong to quickfix1.

I tried to create a patch from a certain revision in quickfix2, but the patch doesn't preserve the commit history. Is there a way to save my commit history, but have a branch without changes in quickfix1?

解决方案

This is a classic case of

# let's go to current master (X, where quickfix2 should begin)

git checkout master

# replay every commit *after* quickfix1 up to quickfix2 HEAD.

git rebase --onto master quickfix1 quickfix2

So you should go from

o-o-X (master HEAD)

\

q1a--q1b (quickfix1 HEAD)

\

q2a--q2b (quickfix2 HEAD)

to:

q2a'--q2b' (new quickfix2 HEAD)

/

o-o-X (master HEAD)

\

q1a--q1b (quickfix1 HEAD)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值