Undo git reset –hard

To remove some unhappy commits I executed a git reset –hard. Unfortunately the hangover of missing some files was shortly after. I’ve read this post about undoing it. And it worked.

This listed a lot of files and commits.

git fsck --cache --unreachable $(git for-each-ref --format="%(objectname)")

I tried a few and was lucky to find what I needed in the top 4 commits.

git show COMMIT HASH

Recovered my files with cherry picking.

git cherry-pick COMMIT HASH

About erictummers

Working in a DevOps team is the best thing that happened to me. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Tooling and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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