brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: a .mailmap file merges your old git names into one

Git
~/tips/tip-git-mailmap-merge-identities

Alice <[email protected]> <[email protected]>

Maps old names and email addresses to one identity in shortlog and log output.

When someone committed with three different email addresses over the years, git shortlog -sn counts them as three people. A .mailmap file in the repository fixes the output without rewriting any history.

Alice <[email protected]> <[email protected]>
Alice <[email protected]> al <[email protected]>

Each line maps an identity as it appears in commits, on the right, to the identity you want to see, on the left. The first line maps an old email; the second maps a name and email combination. Save it as .mailmap at the root and commit it.

Then the counts come out right:

git shortlog -sne HEAD

git log uses the mailmap too, but only in some fields. In a custom format, %aN and %aE give the mapped name and email, while %an and %ae still show what’s in the commit. I think that is easy to miss, and the docs spell it out.

The commits themselves don’t change. The old address is still in the history for anyone who looks at the raw commit, so a mailmap is not a way to hide an address. It only cleans up the display. If you want to stop leaking an address, change user.email for future commits, and accept that the old ones stay unless you rewrite history.

Further reading: gitmailmap documentation, git-shortlog documentation

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link