Skip to content

Instantly share code, notes, and snippets.

@bobjackman
Last active July 12, 2018 13:52
Show Gist options
  • Save bobjackman/8700277 to your computer and use it in GitHub Desktop.
Save bobjackman/8700277 to your computer and use it in GitHub Desktop.
Get a summary of total LOC added, removed, gross line changes, && net total LOC. Credit to (alex)[http://stackoverflow.com/users/887836/alex] modified by (kogi)[http://stackoverflow.com/users/84762/kogi]
#!/usr/bin/env bash
# usage:
# git-stats #gives stats for the whole branch
# git-stats --author="yourname here" #gives stats for specific author
#
# though not all tested, this should be compatible with all limiting options supported by git-log (https://www.kernel.org/pub/software/scm/git/docs/git-log.html#_commit_limiting)
git log --pretty=tformat: --numstat $@ "`git merge-base HEAD develop`..HEAD" | gawk '{ adds += $1 ; subs += $2 ; net += $1 - $2 ; gross += $1 + $2 ; commits += 1 } END { print "total commits\tadded loc\tremoved loc\tgross loc\tnet loc\n"; printf "%d\t%d\t%d\t%d\t%d\n", commits, adds, subs, gross, net }' | column -s $'\t' -t
git log --author="yournamehere" --pretty=tformat: --numstat "`git merge-base HEAD develop`..HEAD" | gawk '{ adds += $1 ; subs += $2 ; net += $1 - $2 ; gross += $1 + $2 ; commits += 1 } END { print "total commits\tadded loc\tremoved loc\tgross loc\tnet loc\n"; printf "%d\t%d\t%d\t%d\t%d\n", commits, adds, subs, gross, net }' | column -s $'\t' -t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment