Skip to content

Instantly share code, notes, and snippets.

@JosuaKrause
Created June 5, 2015 20:20
Show Gist options
  • Save JosuaKrause/43a06f05491d3e7be5aa to your computer and use it in GitHub Desktop.
Save JosuaKrause/43a06f05491d3e7be5aa to your computer and use it in GitHub Desktop.
Blames every line from the diff
#!/bin/bash
cur_file=
cur_commit=
cur_lines=
old_ifs=$IFS
IFS=$'\n'
for line in `git diff -U0 "$@"`; do
case "${line}" in
index*)
# index 12ceb6c..899b332 100755
cur_commit=`echo $line | sed -E 's/^[^\.]+\.\.([0-9a-fA-F]+).+$/\1/'`
;;
diff*)
# diff --git a/file_a b/file_b
# handled below
;;
@@*)
# @@ -12,0 +13 @@ context
cur_lines=`echo $line | sed -E 's/^@@[^+]+\+([0-9,]+) @@.+$/\1/'`
# not sure how to integrate "${cur_commit}"
#echo "'${cur_lines}' '${cur_file}' '${cur_commit}'"
git blame -L "${cur_lines}" -- "${cur_file}" | cat
;;
+++*)
# +++ b/file_b
cur_file=`echo $line | sed -E 's/^[+ ]+b\/(.+)$/\1/'`
;;
---*)
# --- a/file_a
;;
+*|-*)
# ignore
;;
esac
done
IFS=$old_ifs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment