1

我正在和一个合作伙伴一起做一个 git 项目。我做了一些更改,然后意外添加并提交了比我预期更多的文件,并将它们推送到主存储库。如何将远程存储库回滚到最后一次提交,但保留我的本地副本以便我可以重新添加和正确提交?

4

2 回答 2

2

您可以告诉git push将遥控器推送到特定版本:

git push origin HEAD~1:master

解释:

  • origin是远程仓库的名称
  • HEAD~1是 source-refspec - 要推送的修订。 HEAD~1表示当前 local 后面的一个提交HEAD
  • master是 target-refspec - 要推送到的远程分支。
于 2012-12-02T22:43:11.590 回答
1

答案取自这里:如何撤消 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.
于 2012-12-02T22:43:53.333 回答