Git-回滚到上一次提交
我和一个合作伙伴在做一个git项目。我做了一些更改,然后意外地添加并提交了比预期更多的文件,并将它们推送到主存储库。如何将远程存储库回滚到最后一次提交,但保留本地副本,以便正确地重新添加和提交?您可以告诉Git-回滚到上一次提交,git,github,Git,Github,我和一个合作伙伴在做一个git项目。我做了一些更改,然后意外地添加并提交了比预期更多的文件,并将它们推送到主存储库。如何将远程存储库回滚到最后一次提交,但保留本地副本,以便正确地重新添加和提交?您可以告诉git push将远程存储库推送到特定版本: git push origin HEAD~1:master 说明: origin是远程回购的名称 HEAD~1是源refspec–要推送的修订版HEAD~1表示在当前本地HEAD之后提交一次 master是目标refspec–要推送到的远程分支
git push
将远程存储库推送到特定版本:
git push origin HEAD~1:master
说明:
是远程回购的名称origin
是源refspec–要推送的修订版HEAD~1
表示在当前本地HEAD~1
之后提交一次HEAD
是目标refspec–要推送到的远程分支master
$ 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.