Skip to content

Instantly share code, notes, and snippets.

@shellkore
Last active May 19, 2019 08:42
Show Gist options
  • Save shellkore/028f0d1e91fe8eba1c1da6c4fb925d5b to your computer and use it in GitHub Desktop.
Save shellkore/028f0d1e91fe8eba1c1da6c4fb925d5b to your computer and use it in GitHub Desktop.
If you forget to change your name and email intially and made several commits. So, to correct those you can use this script.
  • copy the below code in a file and save it in .sh extension.
  • Configure your OLD_MAIL, CORRECT_NAMEand CORRECT_EMAIL and save the file.
  • This file should be in your directory whose correction you want to do.
  • run this file bash fileName.sh or ./filename
  • force push the repo. git push -f origin master
#!/bin/sh
git filter-branch -f --env-filter '
OLD_EMAIL="oldMail@example.com"
CORRECT_NAME="correctName"
CORRECT_EMAIL="newMail@example.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