1

I have a previous commit (9770912) to which I want temporarily return and make a push to server to see if the bug appeared on site after this commit. Also I want to get back to the current state of code after this. When executed git checkout 9770912, I couldnt make any push or commit.

4

2 回答 2

2

执行 git checkout 9770912 时,我无法进行任何推送或提交。

那是因为您处于分离 HEAD 模式,这意味着您不在分支中(因此,您无法推送该“非分支”)

您可以在该提交上创建另一个分支,并强制将其推送到您的远程主分支

git checkout -b aNewBranch
git push -f origin aNewBranch:master

然后你可以恢复到原来的主人:

git push -f origin master:master
于 2014-02-25T07:13:03.610 回答
0

@vonc 关于分离的 HEAD 是正确的

你应该回到你的头脑

git reset HEAD --hard

在这里你还有两个选择:

通过还原您的提交使其干净并再次推送:

git revert 9770912
git push origin master (I suppose you are on your master)

或者您可以重新设置您的分支并使其消失(更复杂,您将重写历史记录)

git rebase -i HEAD~5 (-i for interactive mode and we will check the five latest commits from the HEAD)

When you are in this mode you should simple delete the line with your commit (with vim for example you can use dd keyboard letter (twice))

Save and quit (:wq)

git push origin master --force (you have to force to rewrite your history and make it disappear)

小心使用这种方法,就好像你有同事一样,它也会与他们最后的历史产生冲突。

于 2014-02-25T08:00:10.970 回答