我有一個先前的提交(9770912),我希望它暫時返回並推送服務器以查看此提交後是否在站點上出現此錯誤。此後我想回到當前的代碼狀態。當執行git checkout 9770912
時,我無法進行任何推送或提交。如何使用之前的git commit進行推送
1
A
回答
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)
要小心這種方法,就好像你有同事一樣,它也會產生與他們最近的歷史衝突。
相關問題
- 1. 如何使用git? git-commit?混帳推?
- 2. 如何在git推後執行git commit?
- 3. git un-remove commit之前?
- 4. 如何在從Git存儲庫進行推送之前測量提交數量?
- 5. Git SVN,如何與遠程推之前進行比較
- 6. 使用Git Commit進行代碼審查
- 7. Doxygen如何在每次推送之前使用git hooks運行doxygen?
- 8. 檢索git commit永不推送
- 9. 如何使用git kraken進行強制推送
- 10. 如何更改推送的git commit的名稱?
- 11. 如何在推送Git之前驗證分支名稱?
- 12. 如何在推送日食之前構建git-commited工作區
- 13. 如何編輯以前的git commit?
- 14. 推送到git時進行部署
- 15. (git add -A後跟git commit)和git commit -a之間的區別?
- 16. 如何配置我的git進行推送?
- 17. 如何使用Intellij編輯以前的git commit消息?
- 18. 恢復以前的git commit?
- 19. 如何設置git以從當前分支進行推送和拉取?
- 20. 我該如何使用特定的linux組來進行git推送?
- 21. 如何使以前的git commit的副本,並使其頭部
- 22. 如何在進行實際的hg推送之前查看將推送到Mercurial回購庫的內容?
- 23. 「git commit」前的多個「git add」
- 24. Git:如何在推送到遠程目錄時進行更新?
- 25. 瞭解何時使用git commit -m和git commit -am
- 26. 什麼時候需要做「git pull」,在「git add,git commit」之前還是之後?
- 27. 如何阻止我使用'git commit -a'?
- 28. 只拿一部分的git commit,推送到github
- 29. 如何使用Git命令行推送更改?
- 30. 當用戶在「git add」和「git commit」之前做「git push」會發生什麼?