Git Reflog to Rescue after Hard Resets

Today I was resetting a local Git repository to previous commits,, in order to trace back some changes which lead to Continious Integration tests failures. I did a few trail and error runs with:

git reset --hard SHA

Where SHA was taken from GitHub or git log. These commands were performed on my local branch which had some new changes commited locally, but not yet pushed to GitHub. Then, I found the working old commit I realized that I am stuck on it! There was a SHA for my latest commit and the command:

git log

wasn’t showing my latest commit either, because I moved the HEAD of the branch behind it. Thansk for an advice, this command saved me:

git reflog BRANCHNAME

It had a short SHA of my latest commit and I was able to reset HEAD back with reset. I knew that Git had my change save, but I wasn’t sure how to get them. As usual Git is a great technology… with a terrible user interface! :-)

Git reflog — a lifesaver!
Git reflog — a lifesaver!

More on git reflog:

Best Regards,
Azat Mardan
Microsoft MVP | Book and Course Author | Software Engineering Leader
Azat Mardan avatar
To contact Azat, the main author of this blog, submit the contact form or schedule a call at and we can go over your bugs, questions and career.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.