Reset Git Committer Email

A common question I get is how to fix a “git” error message like the following:

expected committer email 'me@example.com' but found 'somebody@example.com'

In this case, it is actually a pre-receive hook (YACC) denying the attempted git push.

I suspect the committer email being wrong is the outcome of a botched merge or rebase, but by the time people reach out all evidence has usually been thoroughly destroyed trying to fix the issue. Another source of confusion is that only the author email, but not the committer email, is displayed by default.

A quick check confirms:

$ git log --pretty=full @{u}..HEAD|grep ^Commit:
Commit: Me <me@example.com>
Commit: Me <me@example.com>
Commit: Me <me@example.com>
Commit: Somebody Else <somebody@example.com>
Commit: Somebody Else <somebody@example.com>
Commit: Somebody Else <somebody@example.com>
Commit: Me <me@example.com>
Commit: Me <me@example.com>

If the above command gives an error instead, we might have to set the upstream branch first (and then retry):

$ git branch --set-upstream-to=origin/foo

Here’s how to fix the committer email for all local commits:

$ git filter-branch -f --env-filter '
export GIT_COMMITTER_NAME="Me"
export GIT_COMMITTER_EMAIL="me@example.com"
' --tag-name-filter cat -- @{u}..HEAD

Confirm that the committer has been reset:

$ git log --pretty=full @{u}..HEAD|grep ^Commit:
Commit: Me <me@example.com>
Commit: Me <me@example.com>
Commit: Me <me@example.com>
Commit: Me <me@example.com>
Commit: Me <me@example.com>
Commit: Me <me@example.com>
Commit: Me <me@example.com>
Commit: Me <me@example.com>

Then we try again, hopefully without errors:

$ git push
comments powered by Disqus