Git stats and same but different authors

So you want to know stats: who has done how many things in your git repo.

So you launch `git shortlog` since you know (or your team-mate knows), that it’s good for such things. Alas! More than one email address and perhaps even more than one nick are actually used by one person. And you have a problem. So if you don’t want to read manually then… read on.

You need to map. Mails with people. So, a `.mailmap`.

If `git log –pretty=”%an %ae” | sort -u` gives you:

riddle enigma
Riddle Enigmã
Riddle Enigma
Dr Freeze
Dr Freeze
drFreeze TheVillains

Then, using `git shortlog -sn` yields less-than-satisfactory result:

67 Riddle Enigmã
53 ivyP
48 ivy
29 Dr Freeze
17 Riddle Enigma
6 riddle
3 drFeeze
1 riddleThis

Manual counting be damned, I want that map after all.

`vim .mailmap` # do this in top-level repo dir, where `.gitignore` or `.git` folder are located

## What’s inside?

We have few problems to solve. We want 3 lines (since we have 3 people). We don’t want to deal with Unicode. We want clarity, not obscurity.

  1. Each combo == one line
  2. Ideally we have: Nick <email>
  3. Organization is treated like <email>
  4. Unicode is avoided cause we know nothing about how it’s treated. Option a: one character (a and a tilde-like sign), option b: two characters (a AND the tilde-like sign).

Let’s hit it:

Ivy has three combos so far. Github one and two Gmail-ones. To be smart, we write:

Ivy <>

Ivy <>

Riddle has LOTS of combos. Insane (or is he?). Still, we get clever:

Riddle <> # most gmail ones done

Riddle <TheVillains> # the org, to avoid – email associated with it – as an author

Riddle <>

Doc’s left now:

Freeze <>
Freeze <>

Since .mailmap looks like that:

Ivy <>
Ivy <>
Riddle <>
Riddle <TheVillains> # org to avoid it’s mail as an author
Riddle <>
Freeze <>
Freeze <>

We have what we wanted! git shortlog -sn and

114 Riddle
101 Ivy
32 Freeze


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s