Skip to content

Instantly share code, notes, and snippets.

@steinybot
Last active January 25, 2018 19:58
Show Gist options
  • Save steinybot/60cc7bd759925ad7bf04e45625778511 to your computer and use it in GitHub Desktop.
Save steinybot/60cc7bd759925ad7bf04e45625778511 to your computer and use it in GitHub Desktop.
Git insertions and deletions
git log --shortstat --format="%an" | sed '/^$/d' | awk '
BEGIN { FS = ", " }
{
if (match($1, /^ [0-9]+ files? changed/)) {
split($2, a, " ")
inserts = (a[1] == "")? 0 : a[1]
split($3, b, " ")
deletes = (b[1] == "")? 0 : b[1]
total = (inserts - deletes)
print name " " inserts " " deletes " " total
} else {
name = $0
}
}' | sort | awk '
{
name = $1
for (i = 2; i <= (NF - 3); i++) {
name = name " " $i
}
if (name == previous) {
inserts = inserts + $(NF - 2)
deletes = deletes + $(NF - 1)
total = total + $NF
} else if (previous != "") {
print total ", " previous ", " inserts ", " deletes ", " total
grandTotal = grandTotal + total
inserts = $(NF - 2)
deletes = $(NF - 1)
total = $NF
}
previous = name
}
END {
print grandTotal ", Total, -, -," grandTotal
}
' | sort -rn | cut -d " " -f 2- | column -t -s,
@steinybot
Copy link
Author

This version doesn't quite work properly. I get different totals for three different commands:

git ls-files | xargs wc -l
git summary —line
./git-inserts-deletions.sh

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