Search code examples
gitgraphwc

How can I use git to provide a word count graph?


I'm writing a long piece of prose and want to use git to track the word count. (Not a graph of commits, which is well documented.)

How can I plot a graph of word count vs time (or word count vs commit)?


Solution

  • AFAIK, git doesn't have a feature for word counting, let alone drawing graphs of word counts. However, you can combine git and other tools to do that.

    For example, this will output word counts for each commit that changed file.txt file:

    git rev-list HEAD -- file.txt |
        while read c; do git show "$c:file.txt" | wc -w; done
    

    And this will output the same along with commit timestamps:

    git rev-list --timestamp HEAD -- file.txt |
        while read t c; do echo -n "$t "; git show "$c:file.txt" | wc -w; done
    

    You can feed this output to gnuplot, or paste it into openofice.org Calc to plot a graph.