在git中撤销多个尚未推送到远程的提交

32

我已经运行了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个提交和未暂存的更改。我该怎么做?

2个回答

40

你也可以运行以下命令将代码重置为远程仓库的 HEAD:

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

Ex:

git reset --hard origin/master

27

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

git reset --hard HEAD~4

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接