gitcommand-linerepository

How to count total lines changed by a specific author in a Git repository?


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.


Solution

  • 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