Skip to content

Instantly share code, notes, and snippets.

@tapscodes
Created February 7, 2023 09:50
Show Gist options
  • Select an option

  • Save tapscodes/16558ea1164387b447ffc9ba15d4de64 to your computer and use it in GitHub Desktop.

Select an option

Save tapscodes/16558ea1164387b447ffc9ba15d4de64 to your computer and use it in GitHub Desktop.
Replace old email in old commits made by yourself [works on repos with other users committing] (run this in git bash for best results, removes "verified status" on commits as side effect)
git clone --bare https://github.com/[REPLACE WITH GITHUB USERNAME]/[REPLACE WITH REPO NAME].git
cd [REPLACE WITH REPO NAME].git
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="[REPLACE WITH OLD EMAIL]"
CORRECT_NAME="[REPLACE WITH CURRENT NAME]"
CORRECT_EMAIL="[REPLACE WITH NEW EMAIL (for most people, this is the github email)]"
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
git push --force --tags origin 'refs/heads/*'
cd ..
rm -rf [REPLACE WITH REPO NAME].git
@tapscodes
Copy link
Author

to those who haven't used things like git bash, once you replace the parts that say [REPLACE WITH X], you can paste this entire thing into git bash all at once with a right click. It clones your files, makes the changes, then deletes the files for you all at once.

@tapscodes
Copy link
Author

to find out if a commit uses an old email (and check if this worked), simply add ".patch" to the end of any commit and it will show you the internals including commit name and email right at the top.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment