撤消 git reset --hard origin/master
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26914909/
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 a git reset --hard origin/master
提问by chrisjleu
Working on local master branch:
在本地主分支上工作:
git commit -m "Lots of important commits"
git reset --hard origin/master
How can I retrieve the commits that have been lost as a result of the git reset (from the remote)?
如何检索由于 git reset (从远程)而丢失的提交?
EDIT: note this is not about retrieving uncommitted changes.
编辑:请注意,这与检索未提交的更改无关。
回答by Gabriele Petronella
If you committed it, nothing is lost.
如果你犯了,什么都不会丢失。
If you have the reference of the commit, you can just git reset --hard <sha>
to that precise commit.
如果您有提交的参考,则可以只git reset --hard <sha>
进行精确的提交。
In case you don't you can always use git reflog
to retrieve the sha before performing the hard reset.
如果您不这样做,您可以git reflog
在执行硬重置之前始终使用来检索 sha。
For instance if git reset --hard origin/master
is the last command you run, you can do
例如,如果git reset --hard origin/master
是您运行的最后一个命令,您可以执行
git reset HEAD@{1}