2012-12-02 61 views
1

我正在與合作伙伴一起開發git項目。我做了一些更改,然後意外地添加並提交了比我想要的更多的文件,並將它們推送到主存儲庫。如何將遠程存儲庫回滾到最後一次提交,但保留本地副本,以便我可以重新添加並正確提交?Git - 回滾到之前的提交

回答

2

你可以告訴git push遠程推到某個特定的版本:

git push origin HEAD~1:master 

說明:

  • origin是遠程回購
  • HEAD~1的名稱爲源的Refspec –推動的修訂。 HEAD~1表示在當前本地HEAD之後的一個提交。
  • master是遠程分支推送到的target-refspec –。
+0

謝謝!這工作完美。 – user1436111

1

答案從這裏取:How to undo last commit(s) in Git?

撤消承諾和重做

$ git commit ...    (1) 
$ git reset --soft HEAD^  (2) 
$ edit      (3) 
$ git add ....    (4) 
$ git commit -c ORIG_HEAD  (5) 
This is what you want to undo 

This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both. Leaves working tree as it was before "reset". 

Make corrections to working tree files. 

Stage changes for commit. 

"reset" copies the old head to .git/ORIG_HEAD; redo the commit by starting with its log message. If you do not need to edit the message further, you can give -C option instead.