How to Revert or Undo a Git Hard Reset

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.

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Infrastructure as Code: Introduction to Continuous Spark Cluster Deployment with Cloud Build and…

The Overall Retrospective for Team and Stakeholders

Introduction to Microservices

Basic Kafka for the Uninitiated

Integrating Gesture Controls into your Applications — Kai SDK

Divine providence vs the algorithm

Exciting Features in Tailwind CSS v3.0?

How Webflow change the game of Web Design

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andrew Ly

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

More from Medium

Understanding GIT — A developer’s guide

How to Add a Logo to Your Email Messages in the Inbox

Git, Github, what is it?

Great UNIX Terminal Tips Helps You To Save Time