Skip to content

Instantly share code, notes, and snippets.

@IskenHuang
Last active September 28, 2019 10:03
Show Gist options
  • Save IskenHuang/d50ad4ee04e3af497a51 to your computer and use it in GitHub Desktop.
Save IskenHuang/d50ad4ee04e3af497a51 to your computer and use it in GitHub Desktop.
Change your git commit name. Filter your commit by email to change commit name and email
#!/bin/sh
git filter-branch -f --env-filter '
OLD_EMAIL="$2"
CORRECT_NAME="$3"
CORRECT_EMAIL="$4"
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
#!/bin/sh
# how to use:
# 1. Download this script on your project root
# 2. Change WRONG_COMMIT_EMAIL, YOUR_COMMIT_NAME, YOUR_COMMIT_EMAIL params
# 3. Using Terminal.app on your project root exec '. ./git-author-rewrite.sh'
# 4. Push to your git server again. Please added -f for force push
git filter-branch -f --env-filter '
OLD_EMAIL="WRONG_COMMIT_EMAIL"
CORRECT_NAME="YOUR_COMMIT_NAME"
CORRECT_EMAIL="YOUR_COMMIT_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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment