Skip to content

Instantly share code, notes, and snippets.

@huevos-y-bacon
Last active July 25, 2022 10:16
Show Gist options
  • Save huevos-y-bacon/0ec92610d26f6617294142623f1cb421 to your computer and use it in GitHub Desktop.
Save huevos-y-bacon/0ec92610d26f6617294142623f1cb421 to your computer and use it in GitHub Desktop.
*GIT AUTHOR REWRITES* - use at your own risk
#!/bin/bash
exit
# GIT AUTHOR AND COMMITTER REWRITES - !!!DANGEROUS!!!
# Sources:
# - https://stackoverflow.com/a/1566833
# - https://www.git-tower.com/learn/git/faq/change-author-name-email/
## REWRITE COMMITTER - BY EMAIL
#FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch -f --env-filter '
git filter-branch --env-filter '
WRONG_EMAIL="john.doe@example.com"
NEW_NAME="Jane Doh"
NEW_EMAIL="jane.doh@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$WRONG_EMAIL" ]
then
export GIT_COMMITTER_NAME="$NEW_NAME"
export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$WRONG_EMAIL" ]
then
export GIT_AUTHOR_NAME="$NEW_NAME"
export GIT_AUTHOR_EMAIL="$NEW_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
## REWRITE AUTHOR - BY NAME
#FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch -f --env-filter '
git filter-branch --env-filter '
WRONG_NAME="John Doe"
NEW_NAME="Jane Doh"
NEW_EMAIL="jane.doh@example.com"
if [ "$GIT_AUTHOR_NAME" = "$WRONG_NAME" ]; then \
export GIT_AUTHOR_NAME="$NEW_NAME" GIT_AUTHOR_EMAIL="$NEW_EMAIL"; \
fi
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment