Skip to content

Instantly share code, notes, and snippets.

@tournasdim
Created February 18, 2014 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tournasdim/9079811 to your computer and use it in GitHub Desktop.
Save tournasdim/9079811 to your computer and use it in GitHub Desktop.
simply execute the script to have a summary of Git statistics per author . Just copy the script into "/usr/bin/" directory and make it executable "chmod +x"
#!/bin/bash
LOGOPTS=
END_AND_BEGIN=
#https://github.com/esc/git-stats
#argument parsing
while [ -n "$1" ]; do
case "$1" in
"-s")
shift
END_AND_BEGIN="$END_AND_BEGIN --after=$1"
;;
"-e")
shift
END_AND_BEGIN="$END_AND_BEGIN --before=$1"
;;
"-w")
LOGOPTS="$LOGOPTS -w"
;;
"-C")
LOGOPTS="$LOGOPTS -C --find-copies-harder"
;;
"-M")
LOGOPTS="$LOGOPTS -M"
;;
esac
shift
done
#test if the directory is a git
git branch &> /dev/null || exit 3
echo "Number of commits per author:"
git --no-pager shortlog $END_AND_BEGIN -sn --all
AUTHORS=$(git shortlog $END_AND_BEGIN -sn --all | cut -f2 | cut -f1 -d' ')
for a in $AUTHORS
do
echo '-------------------'
echo "Statistics for: $a"
echo -n "Number of files changed: "
git log $LOGOPTS $END_AND_BEGIN --all --numstat --format="%n" --author=$a | grep -v -e "^$" | cut -f3 | sort -iu | wc -l
echo -n "Number of lines added: "
git log $LOGOPTS $END_AND_BEGIN --all --numstat --format="%n" --author=$a | cut -f1 | awk '{s+=$1} END {print s}'
echo -n "Number of lines deleted: "
git log $LOGOPTS $END_AND_BEGIN --all --numstat --format="%n" --author=$a | cut -f2 | awk '{s+=$1} END {print s}'
echo -n "Number of merges: "
git log $LOGOPTS $END_AND_BEGIN --all --merges --author=$a | grep -c '^commit'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment