Skip to content

Instantly share code, notes, and snippets.

@pstadler
Last active February 9, 2023 13:45
Show Gist options
  • Save pstadler/4722416 to your computer and use it in GitHub Desktop.
Save pstadler/4722416 to your computer and use it in GitHub Desktop.
Print Git commit statistics for a specific author.
# Print Git commit statistics for a specific author
# Usage: git-stats "Linus Torvalds"
git-stats() {
author=${1-`git config --get user.name`}
echo "Commit stats for \033[1;37m$author\033[0m:"
git log --shortstat --author $author -i 2> /dev/null \
| grep -E 'files? changed' \
| awk 'BEGIN{commits=0;inserted=0;deleted=0} \
{commits+=1; if($5!~"^insertion") { deleted+=$4 } \
else { inserted+=$4; deleted+=$6 } } END \
{print "\033[1;34m↑↑\033[1;37m", commits \
"\n\033[1;32m++\033[1;37m", inserted, \
"\n\033[1;31m--\033[1;37m", deleted, "\033[0m"}'
}
@sinhanurag
Copy link

Can this script also handle merge use cases? For instance I merge the remote repo into my branch and then commit my changes. In such a case would the lines inserted deleted only by me be counted pr the merge ones will also be included in the stats?

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