#!/usr/bin/env bash # # Fetch diff stats for the current repo from the last year # Get a commit SHA from a year ago OLD_SHA=$(git log --since="365 days ago" --until="364 days ago" -1 --pretty=format:"%H") NEW_SHA=$(git rev-parse HEAD) # Number of lines then and now OLD_LINES=$(git diff --stat `git hash-object -t tree /dev/null`..$OLD_SHA | awk '/files changed/ {print $4}') NEW_LINES=$(git diff --stat `git hash-object -t tree /dev/null`..$NEW_SHA | awk '/files changed/ {print $4}') # Fetch diff stats echo "Codebase at $OLD_SHA had $OLD_LINES lines" echo "Codebase at $NEW_SHA had $NEW_LINES lines" echo "Diff between these two commits" git diff --numstat $OLD_SHA..$NEW_SHA 2>/dev/null | awk '{ added += $1; removed += $2 } END { print "+" added " -" removed }'