DEV Community

loading...

Discussion on: How to change a git commit author

Collapse
rabbitzzc profile image
rabbit

run this code:

#!/bin/sh

git filter-branch —env-filter '

OLD_EMAIL="xxx@xxx.com"
CORRECT_NAME="YOUR_CORRECT_NAME"
CORRECT_EMAIL="YOUR_CORRECT_EMAIL"

if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$CORRECT_NAME"
    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$CORRECT_NAME"
    export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' —tag-name-filter cat — —branches —tags
Collapse
reobin profile image
Robin Gagnon Author • Edited

I like to have granular control over actions like that though. And usually, I don’t have more than 2 or 3 commits with the wrong author before I notice it.

For other situations though, this is a super useful script. Thanks!