Skip to content

Instantly share code, notes, and snippets.

@earthgecko
Created November 14, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save earthgecko/2450c5d24b6229e773fc to your computer and use it in GitHub Desktop.
Save earthgecko/2450c5d24b6229e773fc to your computer and use it in GitHub Desktop.
Find a change in a git repo via a string in actually git diffs (not just commit messages)
# Find a change via a string in actually git diffs (not just commit messages)
GIT_REPO_DIR="<PATH_TO_YOU_REPO>"
TMP_DIR="/tmp"
STRING_TO_FIND="include openssh_server"
cd "$GIT_REPO_DIR"
> "${TMP_DIR}/git.rev.matches"
git rev-list HEAD |
while read rev; do
if git show -p $rev | grep "$STRING_TO_FIND" >/dev/null; then
echo $rev >> "${TMP_DIR}/git.rev.matches"
fi
done
for rev in $(cat "${TMP_DIR}/git.rev.matches")
do
git show $rev > "${TMP_DIR}/git.show.$rev"
if cat "${TMP_DIR}/git.show.$rev" | grep "$STRING_TO_FIND" > /dev/null; then
echo "
#################
# Found in $rev"
cat "${TMP_DIR}/git.show.$rev" | grep "$STRING_TO_FIND"
fi
done
# To see the whole git show do:
# cat "${TMP_DIR}/git.show.$rev"
# or
# git show $rev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment