How to Revert or Undo a Git Hard Reset

Andrew Ly
Oct 27, 2020

--

Okay, so you made a mistaken commit and you want to go back in time. Fortunately using this code in the terminal has helped:

git reset --hard HEAD~1

But then you’ve taken you too far and you’ve lost precious commits! All of a sudden you’re back to the very beginning and you have no clue how to get back! Rest assured you can! With this:

git reflog

Using this will bring up a log of all the previous commits you made in the past then with using:

git reset --hard HEAD@{whichever number was next to that commit you want to go back to}

And voila! You’re back in business. Hope this article saved ya time and trouble :)

Originally published at https://www.andrewjly.com on October 27, 2020.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Andrew Ly
Andrew Ly

Written by Andrew Ly

Founder of Neo Typewriter. He is a published author, podcast host, digital marketer, and full-stack web developer. Read more at: www.andrewjly.com

No responses yet

Write a response