SharpShade
SharpShade

Reputation: 2163

Get back to latest commit after soft reset

I know there are people having this asked already, but none provided a solution that helped me.

I use GitKraken, which obviously has no integrated functionality for checking out older commits in the history (I had to test a bit, no changes made). I now know that I should have used git checkout HEAD~n but instead used a soft reset. So GitKraken still shows that my changes are there and come after the one I reset to. But how can I get back to my latest commit? Checking out does not work either.

I'm not sure if GitKraken just displays it wrong, but Git tells me that the commit I reset to is the current HEAD. Seems correct.

Any way I can restore the following commits or set them as HEAD?

EDIT for the duplicate tag: The referenced thread is about going back the way it's intended (which I did not do) by checking out a previous commit. Since I did a soft reset the HEAD of my master branch was not the actual latest commit anymore but the one I reset my local repository to. Using git reflog with a reset helped to undo the actions done.

Upvotes: 4

Views: 3269

Answers (1)

Romain Valeri
Romain Valeri

Reputation: 21938

Get it from the branch's reflog.

git reflog [show] [log-options] [<ref>]

So in your case simply

git reflog branch-to-be-fixed

It'll output the list of previous operations on the branch

59a04ab96 branch-to-be-fixed@{1}: commit: ...message...

574c5ca23 branch-to-be-fixed@{2}: commit: ...message...

At this point, spot the commit you need in the output based on its message or hash, and use the handle to reset to the state you want :

git reset --hard branch-to-be-fixed@{1}

Upvotes: 10

Related Questions