I wanted to clear my working directory of some uncommitted files, but accidentally ran git reset --hard
.
I realized that I had lost the previous (un-pushed) commit, so I ran git reset --hard ORIG_HEAD
. This did not get me to my lost commit.
I ran git reflog
, but the commit was not listed there. I also ran git fsck --lost-found
, but there were no commits in the list, only a few unrelated blobs and trees.
Since I can't find any reference of the lost commit (apart from the .git/COMMIT_EDITMSG
which still has the relevant commit message and list of changes), I'm not sure how to go about recovering the commit.
Is there any way to get the lost commit back, or should I get ready for an all-nighter?
git reset --hard
with no commit-ish argument is equivalent togit reset --hard HEAD
, which will not lose commits, pushed or unpushed. It will simply reset your index and working directory back to the state of the last commit you made, losing staged and unstaged (but not yet committed) changes. Thegit reset --hard ORIG_HEAD
is likely to be a problem, depending on what exactly the last command that actually updated ORIG_HEAD was, and how long ago it was, and what you've done in between... – Frothygit reset --hard
. – Koralgit reflog
for that... – Frothy