Phone: +65-8585-1750

Address: 30 Holland Close, Singapore

Fixing up Author and Committer emails in a Repo

Mon, Jul 14, 2014 mdda OSS Blog Comments

Fixing up Author and Committer emails in a Repo

GitHub doesn’t add emails that it doesn’t recognize into your ‘contributor score’ (and activity calendar, etc).

This can be a particular gotcha if one develops on a local machine and commits as ‘username@localhost’ for instance.

Steps to Fix the emails

First, get fully in-sync with the current GitHub state :

git pull
git push

For certainty, update your .git/config to reflect the user you actually want to be :

#more .git/config
...
[user]
    name = Martin Andrews
    email = GitHub@example.com
...

Now, examine which emails need updating :

git log --all --format='Author=%aN <%aE>; Committer=%cN <%cE>' | sort -u

Let’s assume that each of these should actually be GitHub@example.com. For each of the ‘wrong’ user emails :

git filter-branch -f --env-filter '
  m="$GIT_AUTHOR_EMAIL"
  if [ "$GIT_AUTHOR_EMAIL" = "username@localhost" ]
  then
    m="GitHub@example.com"
  fi
  export GIT_COMMITTER_EMAIL="$m"
  export GIT_AUTHOR_EMAIL="$m"
' -- --all

Finally, because this has been a history-slamming change, GitHub requires :

git push -f

All done.

Tags:
linux git github

blog comments powered by Disqus