Skip to content

Instantly share code, notes, and snippets.

@uZer
Created September 7, 2018 22:58
Show Gist options
  • Save uZer/6a795216da8cbc64e118d838a2ef596d to your computer and use it in GitHub Desktop.
Save uZer/6a795216da8cbc64e118d838a2ef596d to your computer and use it in GitHub Desktop.
Change git username/email from all commits matching a certain email
#!/bin/sh
echo "What was your old email? [Default: email@example.com]"
read _WRONG_EMAIL
echo "What name do you want to use? [Default: newuser]"
read _NEW_NAME
echo "What email do you want to use instead? [Default: newuser@example.com]"
read _NEW_EMAIL
echo
OLD_EMAIL=${_WRONG_EMAIL:-email@example.com}
CORRECT_NAME=${_NEW_NAME:-newuser}
CORRECT_EMAIL=${_NEW_EMAIL:-newuser@example.com}
echo "Re-writing history of '${OLD_EMAIL}' to '${CORRECT_NAME}'(${CORRECT_EMAIL})"
git filter-branch --env-filter "
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment