git Git强制恢复到HEAD~7
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3248971/
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
Git force revert to HEAD~7
提问by atp
I committed and pushed some bad things. How do I force revert my local repo to HEAD~7, and re-commit so that HEAD is now at that version? Git docs confuse me.
我承诺并推动了一些不好的事情。如何强制将我的本地存储库恢复到 HEAD~7,并重新提交以便 HEAD 现在处于该版本?Git 文档让我感到困惑。
Thanks!
谢谢!
回答by Greg Bacon
The nicest approach is to push another commit that reverts the unintended commits. See Jakub Nar?bski's answeron how to do that.
最好的方法是推送另一个提交以恢复意外提交。请参阅Jakub Nar?bski关于如何做到这一点的回答。
If for some reason it's worth the potential unfriendliness of pushing an update that isn't a fast-forward (sensitive bits in the commits, for example), give these commands:
如果由于某种原因值得推送不是快进的更新(例如,提交中的敏感位)的潜在不友好性,请提供以下命令:
git reset --hard HEAD~7 git push --force origin master
The first rewinds your current branch. This is a sharp tool, so be careful.
第一个倒带您当前的分支。这是一个锋利的工具,所以要小心。
To stop you accidentally losing work, git won't push your rewound branch. The --force
option disables this safety feature.
为了防止您意外丢失工作,git 不会推送您的倒带分支。该--force
选项禁用此安全功能。
回答by Roman Cheplyaka
git reset --hard HEAD~7
will discard your changes entirely.
git reset --hard HEAD~7
将完全放弃您的更改。
git reset HEAD~7
will drop the commits but leave changes in the working copy, so that you can edit and re-commit them.
git reset HEAD~7
将删除提交但在工作副本中保留更改,以便您可以编辑和重新提交它们。