Last active
June 18, 2024 11:24
-
-
Save DominikStyp/7022353d945ebc21f8bcfa2ca21fdbf0 to your computer and use it in GitHub Desktop.
Git: show number of lines and commits per contributor, count only files: php|js|css|sass|scss
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
#!/bin/bash | |
# provide directory of the repo | |
cd $1; | |
echo "------------- COMMITS ------------"; | |
echo " "; | |
git log --pretty=format:"%an" | sort | uniq -c | sort -nr | awk ' | |
BEGIN { total_commits=0 } | |
{ | |
author = "" | |
for (i=2; i<=NF; i++) author = author " " $i | |
author = substr(author, 2) | |
commits[author] = $1 | |
total_commits += $1 | |
ordered_authors[NR] = author | |
} | |
END { | |
for (i=1; i<=length(ordered_authors); i++) { | |
author = ordered_authors[i] | |
percent = (commits[author] / total_commits) * 100 | |
printf "%-6d %-20s %.1f%%\n", commits[author], author, percent | |
} | |
} | |
' | |
echo " "; | |
echo "------------- LINES OF CODE CHANGED ------------"; | |
echo " "; | |
git log --numstat --pretty=format:"%an" | awk ' | |
BEGIN { total_lines = 0 } | |
{ | |
if ($0 ~ /^[a-zA-Z]/) { | |
author = "" | |
for (i=1; i<=NF; i++) author = author " " $i | |
author = substr(author, 2) | |
} else if (NF == 3 && $3 ~ /\.(php|js|css|sass|scss)$/) { | |
lines_changed[author] += $1 + $2 | |
total_lines += $1 + $2 | |
} | |
} | |
END { | |
for (author in lines_changed) { | |
percent = (lines_changed[author] / total_lines) * 100 | |
printf "%-6d %-20s %.1f%%\n", lines_changed[author], author, percent | |
} | |
} | |
' | sort -nr | |
echo " "; | |
echo "------------- LINES OF CODE ADDED ------------"; | |
echo " "; | |
git log --numstat --pretty=format:"%an" | awk ' | |
BEGIN { total_lines_added = 0 } | |
{ | |
if ($0 ~ /^[a-zA-Z]/) { | |
author = "" | |
for (i=1; i<=NF; i++) author = author " " $i | |
author = substr(author, 2) | |
} else if (NF == 3 && $3 ~ /\.(php|js|css|sass|scss)$/) { | |
lines_added[author] += $1 | |
total_lines_added += $1 | |
} | |
} | |
END { | |
for (author in lines_added) { | |
percent = (lines_added[author] / total_lines_added) * 100 | |
printf "%-6d %-20s %.1f%%\n", lines_added[author], author, percent | |
} | |
} | |
' | sort -nr | |
echo " "; | |
echo "------------- CONTRIBUTORS ACTIVITY PERIOD (time worked on the project) ------------"; | |
echo " "; | |
git log --pretty=format:'%an %ad' --date=short | sort -k1,1 -k2,2 | awk ' | |
{ | |
name = $1; | |
for (i = 2; i <= NF-1; i++) { | |
name = name " " $i; | |
} | |
date = $NF; | |
if (!(name in first)) { | |
first[name] = date; | |
} | |
last[name] = date; | |
} | |
END { | |
for (author in first) { | |
print author "\t" first[author] "\t" last[author]; | |
} | |
}' | sort | awk -F'\t' ' | |
{ | |
print "Author:", $1; | |
print "First Commit:", $1, $2; | |
print "Last Commit:", $1, $3; | |
print ""; | |
}' | |
cd -; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment