我需要做什么:
我有 10 个提交是在 master 上的。我需要将这些提交移动到一个新分支。我一直在定期 pull ,但我还没有 push 我的工作。我怎样才能将我的十次提交放到一个新的分支中,然后我可以推送?

我试过按照 in this question here 的步骤操作,但它们不起作用。具体来说,当我进行 rebase 时,我最终得到的只是 master 上的提交,而我的新分支上没有。没有提交被移动到新分支,我不知道考虑到问题中提供的步骤,这怎么可能。

最佳答案

根据我的理解,这就是你所拥有的:

* commit 10 (master)
|
* commit 9
|
...
|              * (origin/master)
* commit 1     |
|.------------^
*

我认为您要问的是在新分支上提交 1-10 次。

为此,您只需使用分支名称标记分支,然后将 master 重置为 origin/master 所拥有的。

所以:
git checkout master # your current latest set of changes (commit 10)
git branch feature # the name of your branch
git reset --hard origin/master # sets master to point to origin/master
git pull --rebase # updates master with origin/master
git checkout feature && git merge master # updates feature branch with what is on origin/master

这将结束:
* commit 11 (feature) merge commit
|^------------.
* commit 10    |
|              ...
...
|              * (master, origin/master)
* commit 1     |
|.------------^
*

这是你想做的吗?

关于git - 如何将我的十次提交从 master 移动到 git 中的新分支?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16923745/

10-14 14:29
查看更多