Skip to content

Instantly share code, notes, and snippets.

@tobym
Created January 14, 2015 21:30
Show Gist options
  • Save tobym/545e03ac947f2cdad03b to your computer and use it in GitHub Desktop.
Save tobym/545e03ac947f2cdad03b to your computer and use it in GitHub Desktop.
Git extension that shows aggregate --numstat information by author.
#!/bin/bash
# Usage: git stats [options]
# options are any git options that you would pass to "git log", such as "--since 14.days" or path/to/file/or/directory
#
# Prints commit stats alphabetically by author: number of files changes, number of lines inserted, number of lines deleted.
#
# To sort by files changed, use sort like so: git stats | sort -t, -bn -k2
# This tells sort to separate fields by comma, then do a numerical sort on the second field (files changed), ignoring leading whitespace
# (That works with gnu and BSD sort.)
gitargs="$@"
while read author
do
echo -n "$author, "
git log --author "$author" --numstat $gitargs | awk '/^[1-9]/ { files += 1; ins += $1; del += $2 } END { print files " files changed, " ins " insertions(+), " del " deletions(-)" }'
done < <(git log --format='%aN' $gitargs | sort -u)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment