Skip to content

How to Recover a Dropped Git Stash

DodaTech 2 min read

In this tutorial, you'll learn about How to Recover a Dropped Git Stash. We cover key concepts, practical examples, and best practices.

The Problem

You run git stash drop or git stash clear and immediately realize you needed those changes. Or git stash pop applied the stash and then failed to restore it cleanly, leaving your working directory with partial changes. Git doesn't immediately delete the stash data โ€” it's still in the object database as a dangling commit. As long as you haven't run git gc and the commit hasn't been garbage collected, you can recover your stashed work.

Quick Fix

1. Check if the stash is still in the list

git stash list

If it appears here, simply apply it:

git stash apply stash@{0}

2. Find dropped stash commits with git fsck

git fsck --lost-found | grep commit

Expected output:

dangling commit abc123def4567890abc123def4567890abc1234
dangling commit 7890123def4567890abc123def4567890abc1234

3. Inspect each dangling commit

git show abc123def4567890abc123def4567890abc1234

Look for the commit that contains your stashed changes.

4. Apply the found commit

# Create a branch from the recovered stash
git branch recovered-stash abc123def4567890abc123def4567890abc1234

# Or cherry-pick the changes into your current branch
git cherry-pick -n abc123def4567890abc123def4567890abc1234

5. Use git reflog to find stash references

git reflog show stash

If the stash was recently dropped, you might see:

abc1234 stash@{0}: On main: WIP my changes

Apply it directly:

git stash apply stash@{0}

6. Search stashes by content

git fsck --lost-found | grep commit | awk '{print $3}' | while read hash; do
  git show --stat $hash 2>/dev/null | grep -q "filename" && echo "Found: $hash"
done

7. List all unreachable commits

git fsck --unreachable | grep commit | tail -20

Common Causes

Cause Scenario Fix
Accidental git stash drop Dropped the wrong stash Use git fsck --lost-found to find it
git stash clear All stashes removed Check dangling commits with git fsck
git stash pop conflict Stash applied with conflicts, then dropped Apply stash before dropping (apply, not pop)
Terminal closed during pop Partial stash application Find dangling commit in reflog

Practice with a Test Repository

cd /tmp
mkdir git-practice && cd git-practice
git init --initial-branch=main
# Initialized empty Git repository in /tmp/git-practice/.git/
echo "test" > file.txt && git add . && git commit -m "init"
# [main (root-commit) abc1234] init

Before running destructive commands on your real repository, practice on a throwaway test repository. This builds confidence and prevents costly mistakes. The reflog is your safety net, but practice makes it less needed.

Prevention

  • Use git stash apply instead of git stash pop โ€” it leaves the stash in the list for later cleanup
  • Name your stashes: git stash push -m "WIP: login feature"
  • Never run git stash clear โ€” it removes all stashes permanently and irreversibly

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro