Monday, June 9, 2014

Generating Git Stats By Author

Ever wonder how many contributors your git-versioned project has, and how much each of them has contributed to the project. If yes, then here is a simple solution for you. It is based on the git blame command. Observe the section that contains the file extensions, you can customize that to ignore some file extensions.

git ls-tree --name-only -z -r HEAD|egrep -z -Z -E '\.(php|py|html)$'   |xargs -0 -n1 git blame --line-porcelain|grep "^author "|sort|uniq -c|sort -nr


Its not ussually entirely accurate. e.g if a coder adds an if .. else block to enclose existing code, formatting shifts the whole block right by a tab/space and git attributes the authorship of the whole block to this author. Another example is an coder who uses a lot of external libraries and git assumes he is the author.

Nevertheless, its a nice trick to know.