0

不小心我忘了打开一个新分支并将我的更改提交给 master,但没有将它们推送到远程仓库。现在我收到消息:“您的分支在 'origin/master' 之前 1 次提交。”

我想做的是使我的主人与远程仓库的主人相同 - 通过恢复到以前的状态或通过其他方式 - 然后从那里打开一个分支以推送到远程。我不介意重新进行我在之前的意外提交中所做的更改。

当我 :

cemgun@db05:~/mini$ git reset --hard
HEAD is now at 2e2adc9 SHBDN-8584 changes
cemgun@db05:~/mini$ git reset --hard
HEAD is now at 2e2adc9 SHBDN-8584 changes

我仍然在我的意外提交中。

当我 :

cemgun@db05:~/mini$ git checkout -f
Your branch is ahead of 'origin/master' by 1 commit.
cemgun@db05:~/mini$ git checkout -f
Your branch is ahead of 'origin/master' by 1 commit.

我仍然在我的意外提交中。

有什么建议么 ?谢谢你的时间。

4

1 回答 1

2

尝试:

$ git reset --soft HEAD^
$ git checkout -b new_branch

这将撤消最后一次提交,将更改留在工作存储库中,然后创建包含这些更改的 new_branch。然后,您可以在新分支中创建新提交。

于 2012-10-15T11:11:34.100 回答