Skip to content

Instantly share code, notes, and snippets.

@lucasrcezimbra
Last active July 18, 2017 12:25
Show Gist options
  • Select an option

  • Save lucasrcezimbra/f586140270526caf6ddd640f8e68df0a to your computer and use it in GitHub Desktop.

Select an option

Save lucasrcezimbra/f586140270526caf6ddd640f8e68df0a to your computer and use it in GitHub Desktop.
Rewrite name and e-mail on git history
#!/bin/sh
# Rewrite author name and e-mail on git history.
# Rewrites commits not pushed, from origin/HEAD to HEAD (origin/HEAD..HEAD)
# --env-filter https://git-scm.com/docs/git-filter-branch#git-filter-branch---env-filterltcommandgt
# -- origin/HEAD..HEAD https://git-scm.com/docs/git-rev-list#_description
git filter-branch --env-filter '
OLD_EMAIL="MY OLD E-MAIL"
CORRECT_NAME="MY CORRECT NAME"
CORRECT_EMAIL="MY CORRECT E-MAIL"
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' -- origin/HEAD..HEAD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment