Skip to content

git reset --hard caused data loss

Quick summary

You ran git reset --hard and lost uncommitted working tree changes — the changes were not stashed or committed, so they are gone from the working tree.

Why this happens

  • You ran git reset --hard without first stashing or committing uncommitted changes in the working tree

  • You intended git reset --soft or --mixed but used --hard which also wipes the working tree and index

  • A script or alias ran git reset --hard automatically, destroying changes you were still editing

Minimal example

✗ Broken code
echo 'important work' > file.txt
git reset --hard HEAD  # file.txt changes lost!
✓ Fixed code
echo 'important work' > file.txt
git stash  # save changes first
git reset --hard HEAD
git stash pop  # restore changes

Stashing before resetting preserves your changes in the stash list, allowing you to restore them after the reset with git stash pop.

How to diagnose

  • Run git reflog to find the HEAD position before the reset — if changes were staged, the index may still be recoverable

  • Run git fsck --lost-found to search for dangling blobs that might contain the content of your lost files

  • Check your editor's undo history or file system snapshots as a last resort for unsaved changes

How to fix

  • Recover staged content from the index with git fsck --lost-found and inspect .git/lost-found for dangling blobs

  • If the changes were committed before the reset, use git reset --hard <commit-hash> from the reflog to restore them

  • Reconstruct the changes manually from memory, editor backups, or any partial output that was captured before the reset

How to prevent

  • Always git stash or commit before running git reset --hard to preserve a recovery path for uncommitted work

  • Use git reset --mixed (default) instead of --hard when you only want to unstage, not destroy working tree changes

Related Resources

Related Glossary

Related Lessons

← Back to language