Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.