Skip to content

Instantly share code, notes, and snippets.

@bplaxco
Last active July 11, 2024 16:43
Show Gist options
  • Save bplaxco/a6c6e3c5e24a81f5991d722bb98ee5bf to your computer and use it in GitHub Desktop.
Save bplaxco/a6c6e3c5e24a81f5991d722bb98ee5bf to your computer and use it in GitHub Desktop.
Print out the number of commits by year in a repo
#! /usr/bin/env python3
"""
NAME
git-stats
DESCRIPTION
Display the number of commits in a repo by year as a number and histogram.
NOTE
I may tweak it over time to add other stats which is why it's not called something like git-commit-stats.
"""
import sys
import subprocess
from collections import defaultdict
from datetime import datetime
data = subprocess.check_output(["git", "-C", sys.argv[1] if len(sys.argv) > 1 else ".", "log", "--all", "--format=format:%ct"])
dates: list[datetime] = map(datetime.fromtimestamp, map(int, data.splitlines()))
stats = defaultdict(int)
for date in sorted(dates):
stats[date.year] += 1
print("year", "commits", "histogram")
for period, count in stats.items():
print(period, f"{count:7d}", "#" * (count // 100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment