恢复 - git reset --hard HEAD^
不幸的是,我做了几次 git reset --hard HEAD^ ,在几个文件中丢失了相当大的代码块。有没有办法恢复这些提交,或者在这种情况下转发 HEAD 之前的位置,这样我就可以调出我丢失的那些行?
Unfortunately I did several times git reset --hard HEAD^
losing a quite big chunk of code in several files. Is there a way to restore those commits or in this case to forward where the HEAD was before, so I can bring up those lines that I lost?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 reflog 恢复 sha1前一个 HEAD。特别是文章 reflog,你的安全网 将与您特别相关。摘自那篇文章:
找到要返回的提交的 sha1 后,请使用以下内容:
Use the reflog to recover the sha1 of the previous HEAD. In particular, the article reflog, your safety net will be particularly relevant to you. From that article:
Once you have found the sha1 of the commit you want to go back to, use something like:
如果您刚刚提交了代码并且想要撤消该操作,请运行
git reset --hard HEAD@{1}
。请参阅 http://book.git-scm.com/4_git_treeishes.html 中名为“Ordinal Spec”的部分
Run
git reset --hard HEAD@{1}
if you just committed your code and you want to undo that.See Section called "Ordinal Spec" at http://book.git-scm.com/4_git_treeishes.html