5

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?

Community
  • 1
  • 1
Mike
  • 23,892
  • 18
  • 70
  • 90

2 Answers2

6
$ git log --author="<authorname>" --pretty=tformat: --numstat | perl -ane'
> $i += $F[0]; $d += $F[1]; END{ print "added: $i removed: $d\n"}'
jfs
  • 399,953
  • 195
  • 994
  • 1,670
3

Also doable with awk:

git log --author="<authorname>" --pretty=tformat: --numstat | awk -F" " '{ added += $1; removed += $2 } END { print "added: ",  added, "removed:", removed }'
pdbrito
  • 552
  • 8
  • 13