3

I found general statistics on git for all the time the repo has existed but I'm interested in doing something like:

git today 

And get things like # of commits, # of lines , etc. broken down by author.

I am mostly interested in # of lines by current user.. I can combine the results of other things on my own

Kara
  • 6,115
  • 16
  • 50
  • 57
John Tomson
  • 1,411
  • 2
  • 13
  • 14
  • That is a metric you probably [shouldn't even look at](http://stackoverflow.com/questions/3769716/how-bad-is-sloc-source-lines-of-code-as-a-metric). – Quentin Aug 21 '13 at 06:11

3 Answers3

3

If you want to see a graphical representation of a git repository's activity, use the gitstats utility: http://gitstats.sourceforge.net/

All the following commands assume use of, e.g., bash. By running the following command you can get the first commit that has the same date as today.

> first_commit=`git log --pretty=format:"%h" --since "$(date +%Y-%m%-d):00:00"

And the following command will process the git repository for statistics:

> gitstats -c commit_begin=<COMMIT_ID> . target/gitstats

And by combining these we can get a simple command we can set as an alias, if we wish:

> first_commit=`git log --pretty=format:"%h" --since "$(date +%Y-%m%-d):00:00" | tail -n1`; gitstats -c commit_begin=$first_commit . target/gitstats

Then open ./target/gitstats/index.html with your preferred browser

RJo
  • 15,631
  • 5
  • 32
  • 63
2

Well, that's going to require a bit of scripting to accomplish, but I'd suggest you start by looking at the output of this command:

git log --format="format:%ae" --numstat

And also note that git log can also take a --after=<date> argument.

Amber
  • 507,862
  • 82
  • 626
  • 550
  • 2
    for example, `git log --since "$(date +%Y-%m-%d):00:00"` will get all commits since midnight (assuming bash or some other shell with `$()` command substitution) – Useless Aug 20 '13 at 09:00
  • Nice one @Useless, I'll change my answer to use this script instead. – RJo Aug 21 '13 at 06:02
1

Here's a complete script based on RJo's answer:

#!/bin/bash
set -e
TMPDIR=.tmp.gitstat.$$
mkdir $TMPDIR
trap "rm -fr $TMPDIR" EXIT
gitstats -c commit_begin=$(git log --pretty=format:%h --since $(date +%Y-%m-%d):00:00 | tail -1) . $TMPDIR
lynx $TMPDIR/index.html

(obviously replace lynx with your preferred browser, and change the script to either wait for it, or not delete the created directory, if it runs in the background).

Note there's no error checking, and specifically gitstats chokes if there's only one commit (git shortlog -s COMMIT..HEAD must be non-empty).

Useless
  • 64,155
  • 6
  • 88
  • 132