git将提交从一个分支移动到另一个分支

时间:2015-07-06 05:29:44

标签: git

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

创建了BRANCH

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

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

git rebase --onto BRANCH A Z   

但输出不符合预期:

    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

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

enter image description here

1 个答案:

答案 0 :(得分:4)

从Z的主人,复制到BRANCH:

git branch BRANCH

当你还在掌握时,重新回到A:

git reset [--hard] A

BRANCH现在是主人所在的地方,主人现在在A。