Find out how much editing someone has done with git

May 27, 2014

Sometimes I want to know how many edits I’ve made over a time period, so I wrote a little script that pulls the git log and formats it in such a way that your commits are accumulated into a simple report.

14:39 ~/git/zabbix (master)$ git accumulate.pl last week
Deleted 71 and inserted 6 lines

Just place the script somewhere in your PATH.

#!/usr/bin/perl
use strict;

my $author = `git config user.email`;

if ($ARGV[0] =~ /^\S+?\@\S+$/){
        $author = shift;
}

my $since = join( " ", @ARGV );

$since = 'yesterday' if ( $since =~ /^\s*$/ );

chomp( $author );

die "No author set"
        if $author =~ /^\s*$/;

my ($a,$d) = (0,0);

my @results = `git --no-pager log --pretty=oneline --shortstat --author $author --since '$since'`;
chomp for @results;

for (@results){
        chomp;
        if ( /(\d+) insertions/ ){
                $a += $1;
        }

        if ( /(\d+) deletions/ ){
                $d += $1;
        }
}

printf "Deleted %s and inserted %s lines\n", $d, $a;

Discussion, links, and tweets

Follow me on Twitter