Skip to content

Instantly share code, notes, and snippets.

@betandr
Last active March 7, 2019 10:34
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 betandr/e71baa278c6fbe4d41dce424d915a53c to your computer and use it in GitHub Desktop.
Save betandr/e71baa278c6fbe4d41dce424d915a53c to your computer and use it in GitHub Desktop.
Fix commits by incorrect username/email
#!/bin/sh
# USE:
# git update-ref -d refs/original/refs/heads/master
# ...or:
# git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
# If you see:
# Cannot create a new backup.
# A previous backup already exists in refs/original/
# Force overwriting the backup with -f
git filter-branch --env-filter '
OLD_EMAIL="person@example.com"
CORRECT_NAME="The Person"
CORRECT_EMAIL="person@new.com"
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment