Skip to content

Instantly share code, notes, and snippets.

@codeinthehole
Last active February 23, 2022 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codeinthehole/0fff5ec1dfb29f7085d7a2d6d3feca05 to your computer and use it in GitHub Desktop.
Save codeinthehole/0fff5ec1dfb29f7085d7a2d6d3feca05 to your computer and use it in GitHub Desktop.
Analyse the changes in a repo over the last year
#!/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 }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment