git move / migrate从一个分支提交到另一个分支 [英] git move/migrate commits from one branch to another

查看:174
本文介绍了git move / migrate从一个分支提交到另一个分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个新的分支,并将多个提交从MASTER移动到BRANCH。我已经从MASTER commit A创建BRANCH。

I want to create a new branch and move several commits from MASTER to BRANCH. I already created BRANCH from MASTER commit A.

我可以使用 cherry-pick ,但看起来像 rebase 会是更好的选择。

I can use cherry-pick, but looks like rebase would be better choice.

我尝试了一个像这样的命令(来自BRANCH):

I tried a command like this (from BRANCH):

git rebase --onto BRANCH A Z   

但输出结果不符合预期:

but the output is not as expected:

    Note: checking out 'b98885d'.

    You are in 'detached HEAD' state. You can look around, make experimental
    changes and commit them, and you can discard any commits you make in this
    state without impacting any branches by performing another checkout.

    If you want to create a new branch to retain commits you create, you may
    do so (now or later) by using -b with the checkout command again. Example:

    git checkout -b new_branch_name

请指出我在哪里错误 - 谢谢。

Please point out where I got wrong - thanks.

推荐答案

从Z处的master,复制到BRANCH:

From master at Z, copy to BRANCH:

git branch BRANCH

A:

As you’re still on master, reset back to A:

git reset [--hard] A

BRANCH现在是主人的所在,而主人现在在A处。

BRANCH is now where master was, and master is now at A.

这篇关于git move / migrate从一个分支提交到另一个分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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