Skip to content

Instantly share code, notes, and snippets.

@fguillen
Created June 11, 2025 13:56
Show Gist options
  • Save fguillen/d60b35000c2136b7a7ce0fa80e0b9af4 to your computer and use it in GitHub Desktop.
Save fguillen/d60b35000c2136b7a7ce0fa80e0b9af4 to your computer and use it in GitHub Desktop.
Script to count the number of lines written on each commit and calculating num lines/hour
#!/bin/bash
# Navigate to your Git repo before running this script
# LLM generated
commits=($(git rev-list --reverse HEAD))
prev_time=0
printf "%-10s | %-30s | %-14s | %-17s | %s\n" "Commit" "Message" "Lines Changed" "Hours Since Last" "Lines/Hour"
echo "-----------------------------------------------------------------------------------------------"
for commit in "${commits[@]}"; do
short_hash=$(git rev-parse --short "$commit")
message=$(git log -1 --pretty=format:"%s" "$commit" | cut -c1-30)
commit_time=$(git show -s --format=%ct "$commit")
changes=$(git show --shortstat --oneline "$commit" | grep "files changed" | awk '{add+=$4; del+=$6} END {print add + del}')
changes=${changes:-0}
if [ "$prev_time" -ne 0 ]; then
time_diff_sec=$((commit_time - prev_time))
hours=$(echo "scale=2; $time_diff_sec / 3600" | bc)
if (( $(echo "$hours == 0" | bc -l) )); then
lines_per_hour="N/A"
else
lines_per_hour=$(echo "scale=2; $changes / $hours" | bc)
fi
else
hours="0"
lines_per_hour="N/A"
fi
printf "%-10s | %-30s | %-14s | %-17s | %s\n" "$short_hash" "$message" "$changes" "$hours" "$lines_per_hour"
prev_time=$commit_time
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment