Skip to content

Instantly share code, notes, and snippets.

@davidrapson
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidrapson/c23c6f73b2b9fc398f44 to your computer and use it in GitHub Desktop.
Save davidrapson/c23c6f73b2b9fc398f44 to your computer and use it in GitHub Desktop.
List git changes by filetype pattern for an author
#!/bin/sh
author=$1; shift;
patterns=( "$@" );
function get_commits() {
git log --author=$1 --pretty=tformat: --numstat \
| grep $2 \
| awk '{ add += $1; subs += $2; loc += $1 - $2 }
END {
printf "+%s, -%s, %s total (%s:1 +/- ratio)\n",
add, subs, loc, sprintf("%.2f", add / subs)
}'
}
for i in "${patterns[@]}"
do
echo "\nChanges for pattern \"$i\"";
get_commits $author $i;
done
@davidrapson
Copy link
Author

Lists how many changes the author david has made where the file name ends with .scala

❯ ./commits.sh david ".scala$"

Changes for pattern ".scala$"
+2348, -1330, 1018 total (1.77:1 +/- ratio)

Also allows passing multiple patterns, where first argument is the author name and subsequent arguments are patterns to match against. Useful for comparing across languages, for example:

❯ ./commits.sh david ".scss$" ".js$" ".scala$"

Changes for pattern ".scss$"
+13743, -13703, 40 total (1.00:1 +/- ratio)

Changes for pattern ".js$"
+2969, -2567, 402 total (1.16:1 +/- ratio)

Changes for pattern ".scala$"
+2348, -1330, 1018 total (1.77:1 +/- ratio)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment