Skip to content

Instantly share code, notes, and snippets.

@hartym
Forked from netshade/gist:1125810
Created May 3, 2012 09:45
Show Gist options
  • Save hartym/2584767 to your computer and use it in GitHub Desktop.
Save hartym/2584767 to your computer and use it in GitHub Desktop.
git stash grep (bash)
stashgrep() {
for i in `git stash list | awk -F ':' '{print $1}'`; do
git stash show -p $i | grep -H --label="$i" "$1"
done
}
@marianolatorre
Copy link

The code below is quite convenient, it searches across all stashes files containing "plist" and non-case sensitive "basic" in the filename. any change made to a file passing that is concatenated into test.txt then opened.

for sha in $(git rev-list -g stash); do git ls-tree -r $sha:; done | grep plist | grep basic -i | cut -f 1 | cut -d" " -f 3 | sort | uniq | xargs git show > test.txt; open test.txt

@unthought
Copy link

unthought commented May 24, 2017

git stash list -G<regex> is all you need.


git help stash:

list [<options>]
...
The command takes options applicable to the git log command to control what is shown and how. See git-log.

git help log:

-G<regex>
Look for differences whose patch text contains added/removed lines that match <regex>.

@rafbm
Copy link

rafbm commented May 28, 2018

@unthought Beautiful. Thanks so much for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment