关于GitHub:在Git中撤消几个尚未推送到远程的提交

Undo several commits in git which have not pushed to remote

本问题已经有最佳答案,请猛点这里访问。

我已经运行git状态和

1
2
3
4
5
6
7
8
9
10
11
# On branch master
# Your branch is ahead of 'origin/master' by 4 commits.
#   (use"git push" to publish your local commits)
#
# Changes not staged for commit:
#   (use"git add <file>..." to update what will be committed)
#   (use"git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   app/views/layouts/_header.html.erb
#
no changes added to commit (use"git add" and/or"git commit -a")

在提交到我的远程存储库之前,我希望撤消所有4个提交和未准备提交的更改。我该怎么做?


您还可以运行以下命令重置遥控器的头部:

1
git reset --hard <REMOTE>/<BRANCH_NAME>

前任:

1
git reset --hard origin/master


这将丢弃工作树中的所有本地更改和四个最新提交:

1
git reset --hard HEAD~4