Reputation: 18819
I want to see something like an aggregated git log --shortstat --oneline
.
Instead of the following,
2fd8b62 quote sending successfully
5 files changed, 26 insertions(+), 40 deletions(-)
5bc977e Hackedup old (redundant) code so that project compiles
14 files changed, 90 insertions(+), 80 deletions(-)
I want something like
19 files changed, 116 insertions, 120 deletions.
I understand this will contain a lot of redundant data (as files changed may be common, etc.) But I want to track the work done in a day (say) or any time period.
I cannot figure out a simple way to parse the output generated by
git log --shortstat --oneline commit1...commit2
To find the total change, I can do
git diff --shortstat --oneline commit1...commit2
but I do not want this. I am considering each commit to be a valid change, even if it was partially undone in a later commit.
Upvotes: 2
Views: 1021
Reputation: 1324547
This gist gives a possible solution:
git log --shortstat | grep "files changed" | gawk '{files+=$1; inserted+=$4; deleted+=$6} END {print "files changed", files, "lines inserted:", inserted, "lines deleted:", deleted}'
On multiple line, for readability:
git log --shortstat | grep "files changed" | \
gawk '{files+=$1; inserted+=$4; deleted+=$6} END \
{print "files changed", files, "lines inserted:", inserted, "lines deleted:", deleted}'
I just tried it on the git repo, for the 10 past days of commits (it works even on Windows):
c:\prgs\vonc\git\git>
git log --oneline --shortstat --since="10 days ago" | grep "files changed" | gawk '{files+=$1; inserted+=$4; deleted+=$6} END {print "files changed", files, "lines inserted:", inserted, "lines deleted:", deleted}'
files changed 47 lines inserted: 397 lines deleted: 30
That same technique (using gawk
) lets you aggregate other data, like the number of commits per authors:
git log --pretty=format:%an | gawk '{ ++c[$0]; } END { for(cc in c) printf "%5d %s\n",c[cc],cc; }'| gsort -r
git log --pretty=format:%an | \
gawk '{ ++c[$0]; } END \
{ for(cc in c) printf "%5d %s\n",c[cc],cc; }'| gsort
Again, on the git repo, on Windows, it does work:
c:\prgs\vonc\git\git>
git log --pretty=format:%an --since="10 days ago" | gawk '{ ++c[$0]; } END { for(cc in c) printf "%5d %s\n",c[cc],cc; }'| gsort
23 Junio C Hamano
8 Jeff King
3 Johannes Schindelin
Note that it is a bit overkill, in that it includes the merge commits.
Simpler would be
c:\prgs\vonc\git\git>
git shortlog -sn --no-merges --since="10 days ago"
8 Jeff King
6 Junio C Hamano
3 Johannes Schindelin
Upvotes: 2