Skip to content

Instantly share code, notes, and snippets.

@mgeeky
Created November 6, 2019 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgeeky/014da43521fee26c8873bb55b9dedcd2 to your computer and use it in GitHub Desktop.
Save mgeeky/014da43521fee26c8873bb55b9dedcd2 to your computer and use it in GitHub Desktop.
git grep being scripted to run recursively top-down through all of repositories spanning from specified directory. Useful for finding sensitive commits
#!/bin/bash
if [ $# -lt 1 ]; then
echo "Usage: ./git-grep.sh <expression> [path]"
exit 1
fi
path=.
if [ $# -eq 2 ]; then
path=$2
fi
echo "Expression: $1"
echo "Starting path: $path"
for a in $(find $path -name .git -type d -prune )
do
p=$(realpath $a)/../
echo "===========[ $a"
git -C $p grep $1 $(git -C $p rev-list --all 2>/dev/null ) 2> /dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment