Before running this script, you'll need:
The old email address that appears in the author/committer fields that you want to change The correct name and email address that you would like such commits to be attributed to
git clone https://hostname/user/repo.git
cd repo.git
git log --pretty=full | grep -E '(Author|Commit): (.*)$' | sed 's/Author: //g' | sed 's/Commit: //g' | sort -u
4. Copy and paste the script, replacing the following variables based on the information you gathered:
- OLD_EMAIL
- CORRECT_NAME
- CORRECT_EMAIL
git filter-branch --env-filter '
OLD_EMAIL="<old-mail>"
CORRECT_NAME="<correct-name>"
CORRECT_EMAIL="<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 -f -- --all
git log --pretty=full | grep -E '(Author|Commit): (.*)$' | sed 's/Author: //g' | sed 's/Commit: //g' | sort -u
git push --force --tags origin 'refs/heads/*'