2

I want to count up total lines of every committer in a git repository. I only get a solution below:

git log --format='%aN' | sort -u | \
  while read name; do
    echo -en "$name\t"
    git log --author="$name" --pretty=tformat: --numstat | \
    awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -
  done

It can calculate out ALL HISTORY of every committer's total lines. But I want to calculate out in CURRENT snapshot, every committer's total lines. I don't know how to do it.

Do you have a solution about this problem?

paulsm4
  • 99,714
  • 15
  • 125
  • 160
geekzhu
  • 37
  • 3
  • I think you're on the right track (some variation of `git log...` + a sed or awk script). Look [here](https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History) and [here](https://git-scm.com/docs/git-log) for some additional options. – paulsm4 Dec 05 '18 at 03:57
  • Possible duplicate of [GIT contribution per author (lines)](https://stackoverflow.com/questions/25449075/git-contribution-per-author-lines) – phd Dec 05 '18 at 10:29
  • https://stackoverflow.com/search?q=%5Bgit%5D+count+contribution+per+author – phd Dec 05 '18 at 10:30

2 Answers2

1

This is a bit overkill and slow but you can do something like this.

git log --format='%aN' | sort -u | \
  while read name; do
    echo -en "$name\t"
    for FILE in $(git ls-files) ; do git blame $FILE | grep "$name" ; done | wc -l
  done
Pavan Yalamanchili
  • 11,851
  • 2
  • 31
  • 54
0

I found the accepted answer slow and broke for me with GPG signed commits.

This worked:

git ls-files | xargs -n1 git blame --line-porcelain | sed -n 's/^author //p' | sort -f | uniq -ic | sort -nr
rich
  • 17,280
  • 9
  • 58
  • 96