2014-02-25 35 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) 

要小心這種方法,就好像你有同事一樣,它也會產生與他們最近的歷史衝突。

相關問題