gitgit-stash

Is it possible to search through Git stash items?


So I'm learning about using Git stash this week and figured out all of these stashes have been accumulating on my system. I've misplaced some code and I now have a dozen stashes of code 0-11.

Is there a way that I can search through these stashes for a string value in the files within the stash to find the code I'm looking for? Or do I just have to go through and reapply each stash to search/look in them for the code I'm trying to find?


2021/03/18: I have found other information that sort of relates.

You can create a Git alias to search all your stashes. Modify your .gitconfig file and call git stash-search <pattern>.

[alias]
    stash-search = "!f() { git show $(git stash list | cut -d\":\" -f 1) | grep \"$@\" ; }; f" 

Solution

  • git stash show -p stash@{n} | grep "john cena" is the only option I think.

    Of course you can write your own script around that.