block by gka 393f5ab2b95e927d305eb6e14767180e

visualize git logs accross multiple repositories

Are you working too much?

Here’s a simple way to find out!

Just cd into your projects folder (that is, a folder that contains many git repositories) and run this little bash script:

TMPLOG=$(pwd)/tmp-project-log.csv; 
echo "project,timestamp" > $TMPLOG;
for i in *; do; 
   if [ -d $i ] && [ -d $i/.git ]; then;
      cd $i;
      git log --since='last 2 months' --author="$(git config --get user.name)" --pretty=format:"$i,%ai" >> $TMPLOG;
      echo "" >> $TMPLOG;
      cd ..;
   fi;
done;
grep . $TMPLOG > project-logs.csv;
rm $TMPLOG;

Then run this little R script.

needs(readr, dplyr, chron, RColorBrewer)

d <- read_csv('~/nytg/2016/project-logs.csv') %>%
    filter(project != "") %>%
    mutate(ts=as.POSIXct(timestamp)) %>%
    mutate(pid=as.factor(project)) %>%
    mutate(date=as.Date(ts), time=as.POSIXct(format(ts, '%H:%M:%S'), format='%H:%M:%S'))

plot(d$date, d$time, type='n', ylim=rev(range(d$time)))
ticks_time <- seq(as.numeric(as.POSIXct('00:00', format='%H:%M')), as.numeric(as.POSIXct('23:59', format='%H:%M')), 7200)
tick_lbls <- format(as.POSIXct(ticks_time, origin = '1970-01-01'), '%H:%M')
axis(2, at = ticks_time, labels = tick_lbls, las = 2) 

dates <- as.Date(levels(as.factor(d$date)))
weekends <- dates[is.weekend(dates)]
abline(v=dates, col='#f2f2f2', lwd=2)
abline(v=weekends, col='#e9d9d9', lwd=2)

colors <- brewer.pal(8, 'Dark2')
points(d$date, d$time, pch=19, col=colors[as.numeric(d$pid) %% length(colors)], cex=1)

If you don’t have needs, install it via

install.packages('needs')
library(needs)

The resulting plot shows you all your commits over the last 2 months:

plot

Tested on OSX. Feel free to fork and link your version in the comments below.