This question already has answers here:
How do I undo the most recent local commits in Git?
(90个答案)
7年前关闭。
我已经运行了git status并且
我要撤消所有4个提交和未暂存的更改,然后再提交到远程存储库。我怎样才能做到这一点?
(90个答案)
7年前关闭。
我已经运行了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个提交和未暂存的更改,然后再提交到远程存储库。我怎样才能做到这一点?
最佳答案
这将丢弃工作树中的所有本地更改以及四个最新的提交:
git reset --hard HEAD~4