Skip to content

Instantly share code, notes, and snippets.

@thiagoszbarros
Created February 7, 2024 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagoszbarros/f87d44e68981010bc3fa116bce72f70b to your computer and use it in GitHub Desktop.
Save thiagoszbarros/f87d44e68981010bc3fa116bce72f70b to your computer and use it in GitHub Desktop.
script para alterar email do autor dos commits git
#!/bin/bash
OLD_EMAIL="oldmail@email.com"
NEW_EMAIL="newmail@email.com"
# Verify that the old email exists in the commit history
if git log --all --grep="$OLD_EMAIL" --author="$OLD_EMAIL" --oneline --quiet; then
# Rewrite the Git history
git filter-branch --env-filter "
if [ \"\$GIT_AUTHOR_EMAIL\" = \"$OLD_EMAIL\" ]; then
export GIT_AUTHOR_EMAIL=\"$NEW_EMAIL\"
fi
if [ \"\$GIT_COMMITTER_EMAIL\" = \"$OLD_EMAIL\" ]; then
export GIT_COMMITTER_EMAIL=\"$NEW_EMAIL\"
fi
" --tag-name-filter cat -- --branches --tags
echo "Git history rewritten. Please review changes and force-push using:"
echo "git push origin --force"
else
echo "No commits found with the email $OLD_EMAIL."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment