Count Git Blame Lines on Current Files


Here's how to count the number of lines in current files by author.

This doesn't give you total lines added or deleted by author. It doesn't deal with files that used to be there. It only accounts for the latest author on the git blame. And it only accounts for current files.

It will give you a snapshot into who's most recently touched the current state of the code.

This is from a StackOverflow answer.

Throw this in a blame.sh file in the root of your repo:

#!/bin/bash
git ls-tree -r HEAD | while read a b c d
do
    git blame --line-porcelain $d
done | grep '^author ' | sed -e 's/author //' | awk '{a[$0]+=1} END{for(i in a){print i,a[i]}}'

And run, and you'll get something like this:

❯ ./blame.sh
grep: (standard input): binary file matches
Burt 8197
Ernie 2146
Big Bird 6730