How to get your changes back after an accidental hard reset in Git?

If you made `git reset --hard` by mistake, possibilities are you can still get your commit back, as git holds a log of everything for a few days.

If you made git reset --hard by mistake, possibilities are you can still get your commit back, as git holds a log of everything for a few days. This is only valid if your work is backed up, i.e., by committed or stashed. As git reset --hard removes uncommitted changes, so be careful before going into trouble.

The much more reliable choice is to run the following command.

git reset --keep

Alternatively, you can check the list of your past commits and choose the SHA of the commit you want:

git reflog

Now, run the following command to get your changes back:

git reset --hard SHA1234

Originally Posted On: Github (k88hudson)

Subscribe to GIT.WTF!?!

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe