Skip to content

Instantly share code, notes, and snippets.

@chooper
Last active August 29, 2015 14:20
Show Gist options
  • Save chooper/ce87ebd33e7196bc3921 to your computer and use it in GitHub Desktop.
Save chooper/ce87ebd33e7196bc3921 to your computer and use it in GitHub Desktop.
Get the insertions and deletions for the last six months
#!/bin/bash
# Get the insertions and deletions for the last six months
git log --since 'last 6 months' --shortstat master > stats.log
#!/usr/bin/env python
from collections import defaultdict
from pprint import pprint
KEYS = {
'deletion(-)': 'deletions',
'deletions(-)': 'deletions',
'file changed': 'files changed',
'files changed': 'files changed',
'insertion(+)': 'insertions',
'insertions(+)': 'insertions'}
stats = defaultdict(lambda:0)
with open('stats.log', 'r') as f:
content = f.read()
for line in content.split("\n"):
line = line.strip()
shortstats = line.split(',')
for shortstat in shortstats:
if shortstat == '':
continue
shortstat = shortstat.strip()
shortstat_list = shortstat.split(' ', 1)
value, key = shortstat_list
stats[KEYS[key]] += int(value)
pprint(dict(stats))
@chooper
Copy link
Author

chooper commented May 1, 2015

This worked nicely but there were some commits which were major outliers (like a two million line json file that was accidentally checked in)

@chooper
Copy link
Author

chooper commented May 1, 2015

Usage:

./git-stats.sh > stats.log
./stats.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment