Skip to content

Instantly share code, notes, and snippets.

@acorn1010
Created September 26, 2023 22:37
Show Gist options
  • Save acorn1010/6b4e9a101eda1ab8936da77546ebd118 to your computer and use it in GitHub Desktop.
Save acorn1010/6b4e9a101eda1ab8936da77546ebd118 to your computer and use it in GitHub Desktop.
Get lines changed by contributor
#!/bin/bash
# Counts the number of additions + deletions across all commits, grouping commits by contributor.
# Changes are capped at 1,000 changes per commit to limit impact of large scale refactors.
declare -A author_line_changes
# Loop through each commit hash
git log --pretty=format:'%h %aN' | while read commit author; do
# Get the number of additions and deletions for the commit
additions=$(git show --numstat $commit | grep -E '^[0-9]' | awk '{s+=$1} END {print s}')
deletions=$(git show --numstat $commit | grep -E '^[0-9]' | awk '{s+=$2} END {print s}')
# Subtract the changes in package-lock.json
package_lock_additions=$(git show --numstat $commit | grep 'package-lock.json' | awk '{s+=$1} END {print s}')
package_lock_deletions=$(git show --numstat $commit | grep 'package-lock.json' | awk '{s+=$1} END {print s}')
additions=$((additions - package_lock_additions))
deletions=$((deletions - package_lock_deletions))
# If additions or deletions are empty, set them to 0
[ -z "$additions" -o "$additions" -lt 0 ] && additions=0
[ -z "$deletions" -o "$deletions" -lt 0 ] && deletions=0
# Calculate the total line changes for the commit
commit_line_changes=$((additions + deletions))
# If the line changes for this commit are greater than 1000, count them as 1000
if [ "$commit_line_changes" -gt 1000 ]; then
commit_line_changes=1000
fi
# Add the line changes for this commit to the corresponding author's total line changes
author_line_changes["$author"]=$((author_line_changes["$author"] + commit_line_changes))
for author in "${!author_line_changes[@]}"; do
echo "$author: ${author_line_changes["$author"]} line changes"
done
echo ""
done
# Print the total line changes for each author
for author in "${!author_line_changes[@]}"; do
echo "$author: ${author_line_changes["$author"]} line changes"
done
@TiagoRibeiro25
Copy link

Great be ChatGPT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment