oops is in beta. Report any issues on GitHub.

How to undo git reset --hard

May 2026

git reset --hard moves your branch and resets the working tree to match. It is useful, but it can wipe uncommitted work instantly.

If the work was committed

Run git reflog. Find the commit or branch state before the reset, then create a branch from it:

git reflog git switch -c recovery HEAD@{1}

Reflog is often enough for commits because git still knows about those objects for a while.

If the work was uncommitted

This is the dangerous case. git reset --hard overwrites tracked files in the working tree. If the content was never committed or stashed, normal git recovery may not have a copy.

How oops prevents the loss

oops detects git reset --hard before it runs and creates a stash. If the reset was wrong, oops applies that stash back.

$ git reset --hard HEAD~3 $ oops ✓ Undid: git reset --hard Applied stash: stash@{0}

Preview before restoring

Use oops restore --plan to see the stash action before it changes your working tree. That is useful if you have made new edits since the reset.

Install

curl -fsSL oops-cli.com/install.sh | bash

oops also covers git clean, other destructive terminal commands, and AI-agent-triggered resets.