Skip to content

Instantly share code, notes, and snippets.

@SimpleCookie
Created August 28, 2020 09:32
Show Gist options
  • Save SimpleCookie/2f7289882035c4b9105bd0377fca28ef to your computer and use it in GitHub Desktop.
Save SimpleCookie/2f7289882035c4b9105bd0377fca28ef to your computer and use it in GitHub Desktop.
Retrieves stats for authors in a git repo
git log --shortstat --pretty="%cE" | sed 's/\(.*\)@.*/\1/' | grep -v "^$" | awk 'BEGIN { line=""; } !/^ / { if (line=="" || !match(line, $0)) {line = $0 "," line }} /^ / { print line " # " $0; line=""}' | sort | sed -E 's/# //;s/ files? changed,//;s/([0-9]+) ([0-9]+ deletion)/\1 0 insertions\(+\), \2/;s/\(\+\)$/\(\+\), 0 deletions\(-\)/;s/insertions?\(\+\), //;s/ deletions?\(-\)//' | awk 'BEGIN {name=""; files=0; insertions=0; deletions=0;} {if ($1 != name && name != "") { print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net"; files=0; insertions=0; deletions=0; name=$1; } name=$1; files+=$2; insertions+=$3; deletions+=$4} END {print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net";}'
# Credits to Dan and his team
# https://stackoverflow.com/questions/1265040/how-to-count-total-lines-changed-by-a-specific-author-in-a-git-repository
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment