Created
February 7, 2024 11:48
-
-
Save thiagoszbarros/f87d44e68981010bc3fa116bce72f70b to your computer and use it in GitHub Desktop.
script para alterar email do autor dos commits git
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
OLD_EMAIL="[email protected]" | |
NEW_EMAIL="[email protected]" | |
# 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