Blog / git
Get back a git stash your coding agent dropped
Your agent ran git stash drop or git stash clear and your work vanished. Find the lost stash with git fsck, put it back, and keep agents off the stash.
On this page
- Act before git cleans up
- Find the dropped stash
- Put it back
- The stash is still there, but the apply failed
- git stash clear
- What can't come back
- Stop it happening again
- Where Joxo fits
- Frequently asked questions
- Can I recover a dropped git stash?
- How do I find the hash of a dropped stash?
- Does git stash clear delete my work for good?
- Why did git stash pop leave conflict markers?
- Will a recovered stash bring back untracked files?
- Try it with your team
Agents reach for git stash to get a clean working copy before they switch branches or pull. Then they tidy up with git stash drop, or git stash clear to be thorough, and the half-finished work you had lying around is gone from git stash list. It isn't gone from the repository yet. A stash is a commit, and git keeps unreferenced commits for a while before it deletes them. We ran every command here with git 2.43 on a test repository.
Act before git cleans up#
Dropped stashes become unreachable objects. Git removes those during garbage collection, but only once they are older than gc.pruneExpire, two weeks by default. So you have time, just not forever. Don't run git gc --prune=now or git prune while you're looking, and tell your agent not to either.
If the agent printed the drop, the hash is right there in its output:
Dropped refs/stash@{0} (569c96309ed5f69da1ca492e9e14fe5100cefca0)Scroll back through the session or its log. If you have that hash, skip to "Put it back". If not, the next step finds it.
Find the dropped stash#
Ask git for commits nothing points to any more:
git fsck --unreachable --no-reflogs | grep commitunreachable commit ec320bfbea8570920a7f7423c1a96c4905e7b4d9
unreachable commit 0e699e59e2a2276bf03145480bd7a7f1d5e05839
unreachable commit 569c96309ed5f69da1ca492e9e14fe5100cefca0--no-reflogs matters: without it, git treats anything still mentioned in a reflog as reachable, and a dropped stash can hide behind that. Hashes alone don't tell you much, so show each one with its date and message:
git fsck --unreachable --no-reflogs | grep commit | cut -d' ' -f3 \
| xargs git log --no-walk --format='%h %ci %s'ec320bf 2026-11-29 16:43:06 +0000 untracked files on main: e35b1b9 Add retry setting
0e699e5 2026-11-29 16:43:06 +0000 index on main: e35b1b9 Add retry setting
569c963 2026-11-29 16:43:06 +0000 On main: backoff workOne stash makes up to three commits. The one you want has a message starting with On <branch>: (when the stash was given a message with -m) or WIP on <branch>: (when it wasn't). The index on commit holds what was staged, and untracked files on holds files git wasn't tracking yet, saved only when the stash used -u. You never need to apply those two by hand; the main stash commit points to them.
In a busy repository the list can be long, because rebases and amended commits leave unreachable commits too. Filter on the message:
git fsck --unreachable --no-reflogs | grep commit | cut -d' ' -f3 \
| xargs git log --no-walk --format='%h %s' | grep -E '^[0-9a-f]+ (On|WIP on) '569c963 On main: backoff workLook inside before you apply it, to be sure it's the right one:
git stash show -p 569c963That prints the diff the stash would apply, the same as for a stash that's still in the list.
Put it back#
The safest move is to put the commit back into the stash list, so it's protected again while you decide what to do:
git stash store -m "backoff work (recovered)" 569c963
git stash liststash@{0}: backoff work (recovered)Then apply it as usual:
git stash apply
git status --short M retry.py
?? notes.mdBoth the edited file and the untracked notes.md are back, because the stash was made with -u and the recovered commit still points to its untracked part. Use apply rather than pop until you've checked the result; apply leaves the entry in the list.
If you'd rather keep the work on its own branch, git stash branch rescued stash@{0} makes a new branch at the commit where the stash was taken and applies it there, then drops the entry once it applies cleanly. That avoids conflicts with whatever the agent did on your branch since.
The stash is still there, but the apply failed#
Sometimes nothing was dropped. The agent ran git stash pop, it hit a conflict, and the agent moved on. Git prints this when that happens:
CONFLICT (content): Merge conflict in retry.py
The stash entry is kept in case you need it again.So the entry is still in git stash list, and your files now contain conflict markers. Fix the conflicted files and git add them, or throw the half-applied result away with git reset --hard (check git status first: that also discards any other uncommitted edits). Once your working copy is clean, git stash apply again on a branch where it fits. Drop the entry only after the work is safely committed.
git stash clear#
git stash clear removes every entry at once, and git prints nothing. The recovery is the same: every cleared stash is an unreachable commit, and the grep -E '(On|WIP on)' filter above lists them all. Store each one you want back with git stash store, oldest first, so the list ends up in its old order.
What can't come back#
A stash only holds what was in it. Files the agent removed with git clean -fd were never committed or stashed, so git has no copy of them. The same goes for edits thrown away with git restore or git checkout -- <file>. If that's what happened, look for an editor's local history or a backup instead. For files that were committed at some point, see restore a file your coding agent deleted.
Also, git stash without -u leaves untracked files where they are. If they disappeared anyway, something else deleted them, most likely a git clean.
Stop it happening again#
- Commit instead of stashing. A work-in-progress commit on a branch can't be dropped by accident, shows up in
git log, and can be squashed later. Ask your agent, in CLAUDE.md or AGENTS.md, to commit to a branch rather than stash. - Ban drop and clear. Tell the agent never to run
git stash droporgit stash clear. In Claude Code you can add those commands to the deny list in.claude/, so it has to ask.settings.json - Name your stashes.
git stash push -m "why"gives you a message to search for. An entry calledWIP on mainis hard to tell apart from the agent's own. - Keep two people's agents apart. Worktrees share one stash list, so an agent in one worktree can drop a stash made in another. Give each agent its own clone, or use commits; see git worktrees with an agent each.
Where Joxo fits#
When your agent and a teammate's agent share a project, one of them tidying up the other's work is easy to miss until it's gone. In Joxo, an agent can ask before touching a teammate's work, and you answer from the desktop app or your phone. Setup is one line pasted into your agent.
Frequently asked questions#
Can I recover a dropped git stash?#
Usually, yes. A dropped stash is an unreachable commit that git keeps for about two weeks. Find it with git fsck --unreachable --no-reflogs, then run git stash store with its hash to put it back in the list.
How do I find the hash of a dropped stash?#
Look in the output of the drop: git prints "Dropped refs/stash@{0}" followed by the hash. Without it, list unreachable commits with git fsck and look for messages starting with "On" or "WIP on".
Does git stash clear delete my work for good?#
Not right away. Every cleared entry stays as an unreachable commit until garbage collection prunes it, two weeks by default. Recover each one with git stash store.
Why did git stash pop leave conflict markers?#
The stash changed lines that also changed on your branch. Git keeps the entry in the stash list when pop hits a conflict, so you can reset the files and apply it again.
Will a recovered stash bring back untracked files?#
Only if the stash was made with -u or --include-untracked. Those files are saved in a third commit that the stash points to, and git stash apply restores them.