Skip to content

Instantly share code, notes, and snippets.

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 adzenith/fad626b625770771d551c6a34e7d74c7 to your computer and use it in GitHub Desktop.
Save adzenith/fad626b625770771d551c6a34e7d74c7 to your computer and use it in GitHub Desktop.
Get number of lines added and deleted per day from your git repo
#!/bin/bash
usage() {
echo "Usage: $0 BRANCH NUM_DAYS"
exit 1
}
ds() {
date --date="$1 days ago" +%Y-%m-%d
}
if [ $# -lt 2 ] ; then
usage
fi
BRANCH=$1
NUM_DAYS=$2
if ! git rev-parse --verify $BRANCH ; then
echo "Branch with name '$BRANCH' does not exist"
echo
usage
fi
echo "Date,LinesAdded,LinesDeleted"
for day in $(seq 1 $NUM_DAYS)
do
lines=$(git --no-pager log --after=$(ds $day) --before=$(ds $(($day - 1))) --format=format: --numstat $BRANCH | awk '{s+=$1; t+=$2;} END {printf "+%s,-%s",s,t}')
if [[ "$lines" != "+,-" ]]; then
echo "$(ds $day),$lines"
else
echo "$(ds $day),0,0"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment