Skip to content

Instantly share code, notes, and snippets.

@yuan3y
Created April 14, 2017 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save yuan3y/1f7f297ca17f29670963a5d48f6dd967 to your computer and use it in GitHub Desktop.
Save yuan3y/1f7f297ca17f29670963a5d48f6dd967 to your computer and use it in GitHub Desktop.
Get number of lines added and deleted per day from your git repo
#!/bin/bash
ds() {
date --date="$1 days ago" +%Y-%m-%d
}
BRANCH=master # your branch here
echo "Date,LinesAdded,LinesDeleted"
for day in $(seq 1 10)
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",$1,$2}')
if [[ "$lines" != "+,-" ]]; then
echo "$(ds $day),$lines"
else
echo "$(ds $day),0,0"
fi
done
@adzenith
Copy link

adzenith commented Jun 6, 2018

I forked it to take the script and number of days as an argument.
I also had trouble with the awk command on line 12 - I replaced $1,$2 with s,t at the end.

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