Re-writing previous git commits to change committer author/email

If you’ve committed a number of git commits using a wrong user.name or user.email value, you can re-write previous commits with:

git filter-branch --commit-filter '
        if [ "$GIT_COMMITTER_NAME" = "Old Name" ];
        then
                GIT_COMMITTER_NAME="new-name";
                GIT_AUTHOR_NAME="new-name";
                GIT_COMMITTER_EMAIL="new-email";
                GIT_AUTHOR_EMAIL="new-email";
                git commit-tree "$@";
        else
                git commit-tree "$@";
        fi' HEAD

Note that this will re-write all commits on the current branch matching the if condition which may or may not be what you’re looking for, so be careful. push the changes back to your remote origin as needed.

This is based on answers to this question here.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.