Skip to content

Instantly share code, notes, and snippets.

@axzilla
Last active April 26, 2024 07:41
Show Gist options
  • Save axzilla/6df311bf352c5ddf57d6aaa3b0a18722 to your computer and use it in GitHub Desktop.
Save axzilla/6df311bf352c5ddf57d6aaa3b0a18722 to your computer and use it in GitHub Desktop.
Git Identity Rewriter

Description

This Gist contains scripts to update Git author and committer information in the repository history.

# Rewrite All Commits
git filter-branch -f --env-filter '
    GIT_AUTHOR_NAME="name"
    GIT_AUTHOR_EMAIL="example@mail.com"
    GIT_COMMITTER_NAME="name"
    GIT_COMMITTER_EMAIL="example@mail.com"
' HEAD
# Rewrite All Commits filtered by Email
git filter-branch -f --env-filter '
OLD_EMAIL="old@mail.com"
CORRECT_NAME="name"
CORRECT_EMAIL="new@mail.com"
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
' HEAD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment