3days since the last Git and AI fuck-up

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

Sahil Bhatacharyafrom the archive

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.

shell
git reset --keep

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

shell
git reflog

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

shell
git reset --hard SHA1234

Originally Posted On: Github (k88hudson)

Tagged accidents-recovery, git-reset, git-reflog, git-commit