28

我已经运行 git status 和

# 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 次提交和未暂存的更改。我怎样才能做到这一点?

4

2 回答 2

38

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

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

前任:

git reset --hard origin/master
于 2013-05-29T18:05:16.733 回答
26

This will throw away all local changes in the working tree and the four latest commits:

git reset --hard HEAD~4
于 2013-05-29T18:02:38.067 回答