본문 바로가기
DevTools/Git

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

by llHoYall 2021. 2. 15.

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.

'DevTools > Git' 카테고리의 다른 글

[Git] Tip: Cherry-pick from a Different Repository  (0) 2021.11.30
[Git] Tip: Revert Merged Commit  (0) 2021.03.05
[Git] Restore Command  (0) 2020.10.23
[Git] Switch Command  (0) 2020.10.23
[Git] Config Command  (0) 2020.09.23

댓글