Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git-回滚到上一次提交_Git_Github - Fatal编程技术网

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项目。我做了一些更改,然后意外地添加并提交了比预期更多的文件,并将它们推送到主存储库。如何将远程存储库回滚到最后一次提交,但保留本地副本,以便正确地重新添加和提交?

您可以告诉
git push
将远程存储库推送到特定版本:

git push origin HEAD~1:master
说明:

  • origin
    是远程回购的名称
  • HEAD~1
    是源refspec–要推送的修订版
    HEAD~1
    表示在当前本地
    HEAD
    之后提交一次
  • master
    是目标refspec–要推送到的远程分支
以下是答案:

撤消提交并重做

$ 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.