14

I wanted to unlock my last commit and clicked 'undo most recent commit' in the Repository menu. What happened was the the commit disappeared and all the files within that commit. I'm left with '0 Changes' in the file field and I'm back two month worth of changes.

How can I get the FILES back that was in that commit?

JUlinder
  • 995
  • 1
  • 8
  • 19

1 Answers1

34

Here's how I eventually restored my files

From this: https://github.com/blog/2019-how-to-undo-almost-anything-with-git

In terminal enter the root of the repo/application.

run:

git reflog

gives output:

8395eb8 (HEAD -> version2) HEAD@{0}: reset: moving to 8395eb8da1e13f3377829ced60831b84fc9365fb
b95d402 HEAD@{1}: reset: moving to b95d402f746ca053bdd68ee919ed0314155dfc86
b49fbfe HEAD@{2}: revert: Revert "new email design"
b95d402 HEAD@{3}: commit: new email design
8395eb8 (HEAD -> version2) HEAD@{4}: commit: design details

To reset my files from the commit "new email design":

git reset b95d402

where b95d402 is the hash in front of the "new email design"-commit. To have Github Desktop follow the change, I changed the head

git reset --soft HEAD@{4}

Eventually there were a pile of uncommited changes in the pipe which actually are inverted the files that I just restored. Those I just discarded in manually Github.

There might probably be a better way to do this but this returned my files back in Github Desktop.

JUlinder
  • 995
  • 1
  • 8
  • 19
  • 4
    You just saved me alot of time. I accidentally clicked UNDO commit twice and github messed with all my files. Thanks to you I got my latest code back or else I would have had to use some recovery tool or worse, rewrite the code again! – kks21199 Sep 01 '18 at 15:19
  • Thanks! I accidentelly UNDOed away my bitcoin keys and thought I’d lost them. Thanks for this fix! – sandstrom Sep 03 '18 at 18:58