Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redo an 'undo most recent commit' in Github Desktop

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?

like image 389
JUlinder Avatar asked Jan 16 '18 14:01

JUlinder


People also ask

Can you rollback undo a 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.

How do I redo in github?

"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.


1 Answers

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.

like image 139
JUlinder Avatar answered Oct 27 '22 23:10

JUlinder