撤消 git 中尚未推送到远程的多个提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16820861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Undo several commits in git which have not pushed to remote
提问by Wasswa Samuel
I have run git status and
我已经运行了 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")
I want undo all the 4 commits and changes not staged for commit before commiting to my remote repository. How can i do this?
我想在提交到我的远程存储库之前撤消所有 4 次提交和未提交的更改。我怎样才能做到这一点?
回答by nterry
You can also run the following to reset to the remote's HEAD:
您还可以运行以下命令来重置遥控器的 HEAD:
git reset --hard <REMOTE>/<BRANCH_NAME>
Ex:
前任:
git reset --hard origin/master
回答by Klas Mellbourn
This will throw away all local changes in the working tree and the four latest commits:
这将丢弃工作树中的所有本地更改和四个最新提交:
git reset --hard HEAD~4