stashed some code but don't know which stash it is in - how to figure out?

user811433 picture user811433 · Jan 15, 2014 · Viewed 9.9k times · Source

I wrote considerable code for a feature and stashed the changes in git.

After that I pushed several changes into the repository and did a git stash and apply multiple times (read over 100 times).

After almost 2 months I now want to retrieve the changes from git stash – but I cant find them no matter what.

Tried several git stash apply, git stash list, git stash list -p. Nothing works. I cant find those old stashed changes.

Wish I had taken a backup instead of trusting git to stash them...sigh...

Can anyone help?

Answer

Alex Siri picture Alex Siri · Jan 15, 2014

Try this:

git stash list -p | grep 'diff --git' | grep <your file name>

That will find your files in the list. It might take a while.

One thing: git stash apply does not discard a stash. After a successful apply, you should git stash drop so it dos not clutter your list. Personally, I apply the stash using git stash pop.