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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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:
The most common usage of this command is that you’ve just done a
git reset
and moved yourHEAD
back a few commits. But oops, you need that bit of code you left in the second commit. Crap. Now what?
Once you have found the sha1 of the commit you want to go back to, use something like:
git reset --hard 0a1b2c
回答2:
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