Friday, 11 January 2013

Changing the author email for git commits

Say you had configured your email with a typo (say, as [email protected], instead of [email protected]), and want to now fix the email in the git logs, you can do this:

git filter-branch --commit-filter '
    if [ "$GIT_AUTHOR_EMAIL" = "[email protected]" ];
    then
        export [email protected];
        git commit-tree "[email protected]";
    else
        shift;
        while [ -n "$1" ];
        do
            shift;
            map "$1";
            shift;
        done;
    fi'

Remember that it is ok to do this if you have not yet shared your commits to the external world.  However, if you have already shared it, it might not be appropriate to do this, since the filter-branch command creates new commit objects (with different SHA ids than the original commits).

Read more about the git filter-branch command at http://www.kernel.org/pub/software/scm/git/docs/git-filter-branch.html.
Post a Comment

Flattr this blog