Show number of changed lines per author in git Show number of changed lines per author in git git git

Show number of changed lines per author in git


It's an old post but if someone is still looking for it:

install git extras

brew install git-extras

then

git summary --line

https://github.com/tj/git-extras


one line code(support time range selection):

git log --since=4.weeks --numstat --pretty="%ae %H" | sed 's/@.*//g' | awk '{ if (NF == 1){ name = $1}; if(NF == 3) {plus[name] += $1; minus[name] += $2}} END { for (name in plus) {print name": +"plus[name]" -"minus[name]}}' | sort -k2 -gr

explain:

git log --since=4.weeks --numstat --pretty="%ae %H" \    | sed 's/@.*//g'  \    | awk '{ if (NF == 1){ name = $1}; if(NF == 3) {plus[name] += $1; minus[name] += $2}} END { for (name in plus) {print name": +"plus[name]" -"minus[name]}}' \    | sort -k2 -gr# query log by time range# get author email prefix# count plus / minus lines# sort result

output:

user-a: +5455 -3471user-b: +5118 -1934


Since the SO question "How to count total lines changed by a specific author in a Git repository?" is not completely satisfactory, commandlinefu has alternatives (albeit not per branch):

git ls-files | while read i; do git blame $i | sed -e 's/^[^(]*(//' -e 's/^\([^[:digit:]]*\)[[:space:]]\+[[:digit:]].*/\1/'; done | sort | uniq -ic | sort -nr

It includes binary files, which is not good, so you could (to remove really random binary files):

git ls-files | grep -v "\.\(pdf\|psd\|tif\)$"

(Note: as commented by trcarden, a -x or --exclude option wouldn't work.
From git ls-files man page, git ls-files -x "*pdf" ... would only excluded untracked content, if --others or --ignored were added to the git ls-files command.)

Or:

git ls-files "*.py" "*.html" "*.css" 

to only include specific file types.


Still, a "git log"-based solution should be better, like:

git log --numstat --pretty="%H" --author="Your Name" commit1..commit2 | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}'

but again, this is for one path (here 2 commits), not for all branches per branches.