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?
To undo changes associated with a specific commit, developers should use the git revert command. To undo every change that has happened since a given commit occurred, use git reset.
"reset" copies the old head to . git/ORIG_HEAD; redo the commit by starting with its log message. If you do not need to edit the message further, you can give -C option instead.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With