Git - 回滚到之前的提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4407232/
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 - rollback to a previous commit
提问by Ben Aston
I committed my work (note notpushed) in a known good state. I have since made unwanted local changes (without committing or pushing them). What is the command to undo these changes and revert to my previous commit state?
我以已知的良好状态提交了我的工作(注意不是推送)。从那以后,我进行了不需要的本地更改(没有提交或推送它们)。撤消这些更改并恢复到我以前的提交状态的命令是什么?
Please accept my apologies for the beginner question but the suggestions turned up by my googling seem arcane and I would like to be confident in my actions.
请接受我对初学者问题的道歉,但我的谷歌搜索提出的建议似乎很神秘,我想对自己的行为充满信心。
回答by Dan Grossman
From Pro Git Commnuity book:
来自Pro Git 社区书籍:
Fixing mistakes
If you've messed up the working tree, but haven't yet committed your mistake, you can return the entire working tree to the last committed state with
$ git reset --hard HEAD
修正错误
如果你搞砸了工作树,但还没有犯你的错误,你可以将整个工作树返回到最后提交的状态
$ git reset --hard HEAD