Last active
February 23, 2022 11:06
-
-
Save codeinthehole/0fff5ec1dfb29f7085d7a2d6d3feca05 to your computer and use it in GitHub Desktop.
Analyse the changes in a repo over the last year
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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