Extracting a list of committers from Git

time to read 3 min | 518 words

There doesn’t seem to be a nice way to getting stats like “who are the committers in this project” from Git. There is probably some fancy script that does sed/awk magic to do so, but I went with a simpler alternative:

git log --raw > log.txt

var logFile = @"C:\work\ravendb\log.txt";

var committers = from line in File.ReadAllLines(logFile)
                 where line.StartsWith("Author: ")
                 let author = line.Substring("Author: ".Length)
                 group author by author
                 into g
                 let result = new {Committer = g.Key, CommitsCount = g.Count()}
                 orderby result.CommitsCount descending
                 select result;

foreach (var committer in committers)
{
    Console.WriteLine(committer);
}

Running this on Raven’s code produces:

{ Committer = Ayende Rahien <ayende>, CommitsCount = 555 }
{ Committer = Ayende Rahien <Ayende>, CommitsCount = 477 }
{ Committer = unknown <Ayende, CommitsCount = 72 }
{ Committer = Paul B <github, CommitsCount = 24 }
{ Committer = Andrew Stewart <Andrew.Stewart, CommitsCount = 24 }
{ Committer = Benny Thomas <jan.thomas, CommitsCount = 19 }
{ Committer = Luke Hertert <lukehertert, CommitsCount = 15 }
{ Committer = Bobby Johnson <bobby.johnson, CommitsCount = 13 }
{ Committer = Rob Ashton <robashton, CommitsCount = 11 }
{ Committer = unknown <LukeHertert, CommitsCount = 7 }
{ Committer = Andrew Theken <theken.1, CommitsCount = 6 }
{ Committer = AndyStewart <Andy.Stewart, CommitsCount = 3 }
{ Committer = Steve Strong <steve, CommitsCount = 3 }
{ Committer = unknown <Aaron Weiker, CommitsCount = 1 }
{ Committer = Emil Cardell <emil.cardell, CommitsCount = 1 }
{ Committer = bjarte.skogoy <bjarte.skogoy, CommitsCount = 1 }
{ Committer = unknown <henke, CommitsCount = 1 }