DevTools/Git

[Git] Tip: Change committer and author from already committed commit

llHoYall 2021. 2. 15. 21:18

If you use multiple accounts for git, you can make a mistake.

 

I sometimes make a mistake as well.

 

Let's fix this.

 

I made a test repository with a test account.

 

 

Now, do the magic!

 

git filter-branch -f --env-filter '
OLD_EMAIL="old@test.com"
NEW_NAME="NewName"
NEW_EMAIL="new@test.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$NEW_NAME"
    export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$NEW_NAME"
    export GIT_AUTHOR_EMAIL="$NEW_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

 

Now, you can see the log.

 

 

And TaDa~!!

Look at this result!!

 

 

The commit history completely changed as we wish.