Skip to content

Instantly share code, notes, and snippets.

@sbolel
Last active October 24, 2020 02:45
Show Gist options
  • Save sbolel/38973c5aa45898f060590967a244de08 to your computer and use it in GitHub Desktop.
Save sbolel/38973c5aa45898f060590967a244de08 to your computer and use it in GitHub Desktop.
Git: rewrite commit authors
#!/bin/bash
# get the email address to replace
echo " Enter OLD_EMAIL to replace: "
read -r oldEmail
# get the correct authors email to replace with
echo " Enter CORRECT_EMAIL:"
read -r correctEmail
# get the name of the author to replace with
echo " Enter CORRECT_NAME: "
read -r correctName
# backup current git history
cp ./.git ./.git.backup
printf " .git/ copied to .git.backup/"
filter="
OLD_EMAIL=\"$oldEmail\"
CORRECT_NAME=\"$correctName\"
CORRECT_EMAIL=\"$correctEmail\"
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
"
# do replacement
git filter-branch --env-filter "$filter" --tag-name-filter cat -- --branches --tags
printf "... Done.\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment