Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIT contribution per author (lines)

Tags:

git

line-count

I'm trying to print the per-line contribution of each author to a Git repository.

For that, I use the following command, adapted from How to count total lines changed by a specific author in a Git repository?

git ls-tree -r -z --name-only HEAD -- */*.c | xargs -0 -n1 git blame \
--line-porcelain HEAD |grep  "^author "|sort|uniq -c|sort -nr

However, I get the following error:

fatal: cannot stat path 'HEAD': No such file or directory.

What am I doing wrong?

like image 653
morne Avatar asked Aug 22 '14 14:08

morne


People also ask

How are GitHub contributions calculated?

Whenever you commit to a project's default branch or the gh-pages branch, open an issue, or propose a Pull Request, we'll count that as a contribution. Repositories are sorted by your recent impact. A commit today is worth more than a commit last week.

Does git blame shows the lines that were deleted or replaced?

The report does not tell you anything about lines which have been deleted or replaced; you need to use a tool such as git diff or the "pickaxe" interface briefly mentioned in the following paragraph.


2 Answers

Okay, after more investigation I found this on SO.

git ls-files -z | xargs -0n1 git blame -w | perl -n -e '/^.*?\((.*?)\s+[\d]{4}/; print $1,"\n"' | sort -f | uniq -c | sort -n  

The answer came with support from Eric Z

RESULT

    234926 USER 1
     32453 USER 2
   2941234 USER 3
like image 169
morne Avatar answered Oct 26 '22 19:10

morne


This means the first part of your expression is not giving any results. Try

git ls-tree -r -z --name-only HEAD -- */*.c

without the latter part; probably that gives you empty output. Fix that expression to list the files you want to work on... If I use that in a repository not containing any .c files; it gives me the same error as you. Either removing the option */*.c or fixing it to */*.cpp fixed it (depending on the outcome you want)

like image 39
Chris Maes Avatar answered Oct 26 '22 18:10

Chris Maes