Created
November 6, 2019 14:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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