Search code examples
gitmetricslines-of-code

How to create LOC data in git?


I want to track the improvement of a project over time in git.

I need line of code statistics by time. For example.

Time        LOC
-----       -----
01/01/2015 29021
01/08/2015 29987
......

gitstats is throwing some weird error. So I need another alternative.

Any ideas?


Solution

  • Here's the start of an idea.

    You could have a little script which checks out a ref, and outputs all non-binary code content with:

    #!/bin/sh
    # catAll.sh
    git checkout $1;
    for i in `git grep --cached -Il ''`; do
        cat $i
    done
    

    Then, pipe that output to wc to get the LOC:

    catAll.sh | wc -l
    

    Get the date of a commit with:

    git show -s --format=%ci <sha>
    

    Then, (and this could take long time to run depending on the size of your repo) run the command with HEAD, HEAD~, HEAD~~, etc.

    This would involve a little scripting to put it all together, but could be wrapped in a nice command to spit out the last, say 5, commit points.