Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I sum up the lines added/removed by a user in a git repo?

Tags:

git

scripting

I am trying to find the total number of lines added and total number of lines removed by a user in a git repository. I looked at How to count total lines changed by a specific author in a Git repository?, which had the command git log --author="<authorname>" --pretty=tformat: --numstat, but the answer failed to give a script(however simple) to total the lines changed. What's the simplest way to sum up the lines added/removed?

like image 936
Mike Avatar asked May 09 '10 03:05

Mike


2 Answers

$ git log --author="<authorname>" --pretty=tformat: --numstat | perl -ane'
> $i += $F[0]; $d += $F[1]; END{ print "added: $i removed: $d\n"}'
like image 64
jfs Avatar answered Oct 22 '22 16:10

jfs


Also doable with awk:

git log --author="<authorname>" --pretty=tformat: --numstat | awk -F" " '{ added += $1; removed += $2 } END { print "added: ",  added, "removed:", removed }'
like image 27
pdbrito Avatar answered Oct 22 '22 15:10

pdbrito