Recover from git reset --hard?
Solution 1:
answer from this SO
$ git reflog show
4b6cf8e (HEAD -> master, origin/master, origin/HEAD) HEAD@{0}: reset: moving to origin/master
295f07d HEAD@{1}: pull: Merge made by the 'recursive' strategy.
7c49ec7 HEAD@{2}: commit: restore dependencies to the User model
fa57f59 HEAD@{3}: commit: restore dependencies to the Profile model
3431936 HEAD@{4}: commit (amend): restore admin
033f5c0 HEAD@{5}: commit: restore admin
ecd2c1d HEAD@{6}: commit: re-enable settings app
# assuming you want to get back to 7c49ec7 (restore dependencies to the User model)
$ git reset HEAD@{2}
You got your day back! :)
Solution 2:
You cannot get back uncommitted changes in general.
Previously staged changes (git add
) should be recoverable from index objects, so if you did, use git fsck --lost-found
to locate the objects related to it. (This writes the objects to the .git/lost-found/
directory; from there you can use git show <filename>
to see the contents of each file.)
If not, the answer here would be: look at your backup. Perhaps your editor/IDE stores temp copies under /tmp or C:\TEMP and things like that.[1]
git reset HEAD@{1}
This will restore to the previous HEAD
[1] vim e.g. optionally stores persistent undo, eclipse IDE stores local history; such features might save your a**