Skip to content

Instantly share code, notes, and snippets.

@boywijnmaalen
Last active April 9, 2018 05:14
Show Gist options
  • Save boywijnmaalen/82f185dd9f0ee52531bc to your computer and use it in GitHub Desktop.
Save boywijnmaalen/82f185dd9f0ee52531bc to your computer and use it in GitHub Desktop.
Changing the Git history of your repository using a script
# 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