Update All Previous Git Commit Author Name & Email

1. Create a bash script with the following content

echo "Enter Old Email address: "
read OLD_EMAIL
echo "Enter new Email Address: "
read CORRECT_EMAIL
echo "Enter new user name (First name + Last Name): "
read CORRECT_NAME

env_filter="
OLD_EMAIL=\"$OLD_EMAIL\"
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
"

git filter-branch --env-filter "$env_filter" --tag-name-filter cat -- --branches --tags

rm -rf .git/refs/original/refs/*/*

2. Delete duplicate backup history

Delete the “original” backup that is created after executing the script:

git update-ref -d refs/original/refs/heads/master

3. Remove original refs folder

Check if .git/refs/original is empty, then remove it:

rm -rf .git/refs/original

4. Verify the updated logs

git log --pretty=format:"[%h] %cd - Committer: %cn (%ce), Author: %an (%ae)"

5. Force push

git push --force --tags origin HEAD:master

References