2014-02-25 60 views
1

我有一个先前的提交(9770912),我希望它暂时返回并推送服务器以查看此提交后是否在站点上出现此错误。此后我想回到当前的代码状态。当执行git checkout 9770912时,我无法进行任何推送或提交。如何使用之前的git commit进行推送

回答

2

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

那是因为你是在一个detached HEAD mode,这意味着你是不是在一个分支(这样,你不能推说“非分支”)

你可以做的是提交另一个分支,并迫使其推送到你的远程主分支

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

然后你就可以恢复是什么大师:

git push -f origin master:master 
0

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

你应该回到你的头

git reset HEAD --hard 

,在这里你也有2种选择:

让它干净的复归你的提交并再次推送:

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) 

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

相关问题