Is there a command I can invoke which will count the lines changed by a specific author in a Git repository? I know that there must be ways to count the number of commits as Github does this for their Impact graph. Thanks in advance!
views:
443answers:
4You want Git blame.
There's a --show-stats option to print some, well, stats.
The output of the following command should be reasonably easy to send to script to add up the totals:
git log --author="<authorname>" --oneline --shortstat
This gives stats for all commits on the current HEAD. If you want to add up stats in other branches you will have to supply them as arguments to git log
.
For passing to a script, removing even the "oneline" format can be done with an empty log format, and as commented by Jakub Narębski, --numstat
is another alternative. It generates per-file rather than per-line statistics but is even easier to parse.
git log --author="<authorname>" --pretty=tformat: --numstat
To count number of commits by a given author (or all authors) on a given branch you can use git-shortlog; see especially its --numbered
and --summary
options, e.g. when run on git repository:
$ git shortlog v1.6.4 --numbered --summary
6904 Junio C Hamano
1320 Shawn O. Pearce
1065 Linus Torvalds
692 Johannes Schindelin
443 Eric Wong
In addition to Charles Bailey's answer, you might want to add the -C
parameter to the commands. Otherwise file renames count as lots of additions and removals (as many as the file has lines), even if the file content was not modified.
To illustrate, here is a commit with lots of files being moved around from one of my projects, when using the git log --oneline --shortstat
command:
9052459 Reorganized project structure
43 files changed, 1049 insertions(+), 1000 deletions(-)
And here the same commit using the git log --oneline --shortstat -C
command which detects file copies and renames:
9052459 Reorganized project structure
27 files changed, 134 insertions(+), 85 deletions(-)
In my opinion the latter gives a more realistic view of how much impact a person has had on the project, because renaming a file is a much smaller operation than writing the file from scratch.