Skip to main content

Modify Git Log Mail

Use the following command to replace commit email and author information:

git filter-branch --env-filter '
if [ "$GIT_COMMITTER_EMAIL" = "old@example.com" ]
then
    export GIT_COMMITTER_NAME="new"
    export GIT_COMMITTER_EMAIL="new@example.com"
fi
if [ "$GIT_AUTHOR_EMAIL" = "old@example.com" ]
then
    export GIT_AUTHOR_NAME="new"
    export GIT_AUTHOR_EMAIL="new@example.com"
fi
' -- --all

Description

This command rewrites the author and committer information for all commits in the entire Git repository history. If a commit contains the specified old email address old@example.com, it will be replaced with the new username and email.


Logic Details

  • Traverse the entire repository history (-- --all refers to all branches)
  • For each commit:
    • If GIT_AUTHOR_EMAIL is old@example.com, change the author name to new and email to new@example.com
    • If GIT_COMMITTER_EMAIL is old@example.com, change the committer name to the same new values
  • The result is a completely rewritten version of the history, with all commit information updated to the new identity