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?
views:
54answers:
1
+6
A:
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
Greg Hewgill
2010-07-15 22:31:21
Great! Thanks that did the job perfectly.
Lan
2010-07-15 22:37:54
You can also reset to `HEAD@{n}`, finding the appropriate n from the reflog
Michael Mrozek
2010-07-15 22:57:39
One can also view the reflog with `git log -g`, which might provide a bit more context than `git reflog show`.
Chris Johnsen
2010-07-16 04:04:54