Last active
April 9, 2018 05:14
-
-
Save boywijnmaalen/82f185dd9f0ee52531bc to your computer and use it in GitHub Desktop.
Changing the Git history of your repository using a script
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
# vim git-author-rewrite.sh | |
# Copy and paste the script, replacing the following variables based on the information you gathered: | |
``` | |
#!/bin/sh | |
git filter-branch --env-filter ' | |
OLD_EMAIL="<old email address>" | |
CORRECT_NAME="<name>" | |
CORRECT_EMAIL="<new email address>" | |
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 | |
``` | |
# make it writable | |
$ chmod +x git-author-rewrite.sh | |
# execute | |
$ ./git-author-rewrite.sh | |
# double check changes | |
$ git log | |
# force push the changes | |
$ git push --force --tags origin 'refs/heads/*' | |
# change email address local repo | |
$ git config user.email "[email protected]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment