Find all the Git commits that modified a particular line in a file.
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 | |
# Sample use: | |
# PATTERN="\"/some-route\"" FILE=config/routes.rb ~/bin/git-line-history.sh | |
# Thanks to mikedillion <https://github.com/mikedillion> for the basis of this! | |
set -e | |
#PATTERN="version':" | |
#FILE="setup.py" | |
if [ -z "$REF" ]; then | |
REF=HEAD | |
echo "Starting with $REF" | |
fi | |
if [ -z "$FILE" ]; then | |
echo "Pass FILE environment variable" | |
exit 1 | |
fi | |
if [ -z "$PATTERN" ]; then | |
echo "Pass PATTERN environment variable" | |
exit 1 | |
fi | |
if [ -z "$REPO_URL" ]; then | |
REPO_URL="https://github.com/your-favorite/default-repo" | |
echo "Assuming REPO_URL should be $REPO_URL" | |
fi | |
while true; do | |
BLAME_LINE=$(git blame $REF^ $FILE | grep "$PATTERN") | |
NEW_REF=$(echo $BLAME_LINE | awk '{print $1}') | |
echo "$NEW_REF - $REPO_URL/commit/$NEW_REF" | |
REF=$NEW_REF | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment