DEV Community

Cover image for How to change the author of all your commits

How to change the author of all your commits

Christian Vasquez on September 28, 2018

As a wise man once said: "With great power comes great responsibility" - Benjamin Parker character from the Spider-man comics. This should not ...
Collapse
 
hoelzro profile image
Rob Hoelz •

Great tip! As an alternative, if you're uncomfortable rewriting all of a project's history using git-filter-branch, Git has a feature known as mailmaps which allow you to canonicalize username and e-mail addresses.

Collapse
 
chadasapp profile image
Chad Horohoe •

Far better solution!

Collapse
 
johnjoseph profile image
John Bachir •

Thanks for this! mailmap doesn't come up in google searches as much as one might expect, it's a perfect solution for me

Collapse
 
waxrat profile image
m¡chael cook 🐌 • • Edited

Here's an example of how to fix the email address of commits.
Don't rewrite all commit authors, only the commits with the incorrect email address.

git filter-branch --env-filter '
   if [ "$GIT_AUTHOR_EMAIL" = root@localhost ]; then
     GIT_AUTHOR_EMAIL=michael@example.com
   fi
 ' HEAD
Enter fullscreen mode Exit fullscreen mode
Collapse
 
nickytonline profile image
Nick Taylor • • Edited

Helpful post. Thanks for sharing Christian.

We rebase at work which means we need to force a push. However, you can use a slightly safer force command.

Having said that, I renamed that alias a while back to pf. More aliases here.

Collapse
 
chrisvasqm profile image
Christian Vasquez • • Edited

That sounds awesome! I'll give it a try!

Collapse
 
themulti0 profile image
Multi •

Thanks! Very helpful. Thanks for sharing. I will definitely use that whenever I encounter a problem like that.

Collapse
 
ben profile image
Ben Halpern •

Nice helpful post 😄

Collapse
 
ld00d profile image
Brian Lampe •

Thank you for this post. I had the exact same situation. In my case, most of the commits were under my work email.

Collapse
 
hoverbaum profile image
Hendrik •

Sweet and concise post, thanks a lot. This is a problem I have run into way more than I would like to admit 🙈