Skip to content

Instantly share code, notes, and snippets.

@ttaylorr
Created March 27, 2017 16:28
Show Gist options
  • Save ttaylorr/3c1fb0c843d2f3387dff044b382084b8 to your computer and use it in GitHub Desktop.
Save ttaylorr/3c1fb0c843d2f3387dff044b382084b8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
name="$1"
if [ -z "$name" ]; then
echo >&2 "usage: "$0" <filename>"
exit 1
fi
what="$(git ls-files -s | grep "\t$name$" | awk '{ print $2 }')"
while read l; do
sha="$(echo "$l" | awk '{ print $1 }')"
tree="$(git ls-tree "$sha" -r)"
dtree="$(git diff-tree -r --no-commit-id "$sha")"
found="$(echo "$tree" | grep -c "$what")"
dfound="$(echo "$dtree" | awk '{ print $4 }' | grep "$what")"
if [ "0" -ne "$found" ]; then
echo " found $what in $sha";
fi
if [ ! -z "$dfound" ]; then
echo "$what introduced in $sha";
exit 0
fi
done < <(git log --oneline)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment