Skip to content

Instantly share code, notes, and snippets.

@KtanPatel
Created January 7, 2021 06:10
Show Gist options
  • Save KtanPatel/38ffb52bb978746505fcf1be06181a98 to your computer and use it in GitHub Desktop.
Save KtanPatel/38ffb52bb978746505fcf1be06181a98 to your computer and use it in GitHub Desktop.
Change author name and email for multiple commits - GIT
#!/bin/sh
# usage : $ ./change-author-git.sh <old email> <correct email> <correct name>
# example: $ ./change-author-git.sh oldemail@mail.com newemail@mail.com "Ketan Patel"
git filter-branch --env-filter '
OLD_EMAIL=$1
CORRECT_EMAIL=$2
CORRECT_NAME=$3
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 -- --branches --tags
# remove duplicate backup history
git update-ref -d refs/original/refs/heads/master
# remove folder
rm -rf .git/refs/original
# verify the new rewritten log
git log --pretty=format:"[%h] %cd - Committer: %cn (%ce), Author: %an (%ae)"
# remove git log - which has some log files that still have your old name (optional)
# rm -rf .git/logs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment