Skip to content

Instantly share code, notes, and snippets.

@romuald
Last active November 18, 2020 16:03
Show Gist options
  • Save romuald/90968156879cfa977ae57cf79c4eb57e to your computer and use it in GitHub Desktop.
Save romuald/90968156879cfa977ae57cf79c4eb57e to your computer and use it in GitHub Desktop.
git blame, kind of recursively
#!/bin/bash -e
# Small script to blame a file and recursivelly go through possible previous commits
# Needs the "xsel" binary / package installed
# Usage: reblame filename
# - will git blame the file on the HEAD
# - (user) X11 select commit id
# - show commit or git blame the parent of the selected commit
# - repeat
filename=$1
hash=HEAD
reblame=1
while :; do
if [ -n "$reblame" ]; then
git blame "$hash" -- "$filename"
hash=$(xsel -o)
fi
read -p "[S]how or [d]ig? ($hash) " input
if [ -z "$input" -o "$input" == "S" -o "$input" == "s" ]; then
git show $hash
reblame=""
elif [ "$input" == "D" -o "$input" == "d" ]; then
hash=$hash^
reblame=1
else
break
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment