The best resources for developers

How can I graph Lines of Code history in a Git repo?

git log --shortstat --reverse --pretty=oneline

Display the per-commit size of the current git branch.

import subprocess
import re
import sys

def main(argv):
  git = subprocess.Popen(["git", "log", "--shortstat", "--reverse",
                        "--pretty=oneline"], stdout=subprocess.PIPE)
  out, err = git.communicate()
  total_files, total_insertions, total_deletions = 0, 0, 0
  for line in out.split("
    if not line: continue
    if line[0] != " ": 
      # This is a description line
      hash, desc = line.split(" ", 1)
      # This is a stat line
      data = re.findall(
        " (d+) files changed, (d+) insertions(+), (d+) deletions(-)", 
      files, insertions, deletions = ( int(x) for x in data[0] )
      total_files += files
      total_insertions += insertions
      total_deletions += deletions
      print "%s: %d files, %d lines" % (hash, total_files,
                                        total_insertions - total_deletions)

if __name__ == "__main__":

Tags: ruby python git lines-of-code

Source: By dbr as answer to the question

This code snippet was collected from stackoverflow, and is licensed under CC BY-SA 3.0

Related code-snippets: