Search code examples
gitgit-stash

How can I search all my Git stashes for a particular string?


git log --all -S <search-term> searches the full history of all branches for changes that added or removed a given search term. Super powerful. Super cool.

But what if the change I am looking for was never committed to a branch, but was instead tucked away in a Git stash? Is there an easy way to search all of them for a particular string?

(I realise that stashes are a bad place to keep anything of importance for any length of time and that temporary branches are a better solution. I also realise that one's stash count should generally be kept pretty low. But best practices aside, I was just in a situation where I know I wrote some code months ago, but could not find it anywhere. Manually checking through my stashes to look for that code was a tedium I would prefer not to experience again.)


Solution

  • git stash list takes the same options as git log. So you can do git stash list -S <search term>.