11
Apr

Fix author of git commits

Sometimes, when I started a new git repository, I have to realize that I did some commits using the wrong user name or e-mail information. Yes, I have many identities, for example one with my work e-mail address and one with my personal e-mail address.

Updating this history information is not so easy and it’s much more difficult, when we already pushed these commits to a remote repository. It is good, that it’s difficult, because it changes the commits and therefore also changes the commit-IDs. But, as already mentioned, in most cases this happens at the very beginning of a project, when I was the only one who did commits, so here’s my simple solution.


Only run these commands if you were the only one who committed to this repository! It overwrites ALL authors of ALL commits and with this it also overwrites ALL commit-IDs. So, be careful!
# update the author e-mail address
git filter-branch --env-filter 'GIT_AUTHOR_EMAIL="jasonleroy@leranda.com"; export GIT_AUTHOR_EMAIL'
# remove the backup branch
git update-ref -d refs/original/refs/heads/master

# update the author name
git filter-branch --env-filter 'GIT_AUTHOR_NAME="Jason Leroy"; export GIT_AUTHOR_NAME'
# remove the backup branch
git update-ref -d refs/original/refs/heads/master

# re-push all commits to the remote repository
git push --force

There's 0 Comment So Far

Share your thoughts, leave a comment!