Skip to content

Instantly share code, notes, and snippets.

@GeorgeGedox
Created June 27, 2019 00:06
Show Gist options
  • Save GeorgeGedox/e8a09bb76bd0787459b87cac0d8523f7 to your computer and use it in GitHub Desktop.
Save GeorgeGedox/e8a09bb76bd0787459b87cac0d8523f7 to your computer and use it in GitHub Desktop.
Change commit author history based on email across all branches
#!/bin/sh
GIT_REPOSITORY="https://github.com/user/repo.git"
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
git clone --bare $GIT_REPOSITORY TMP_REPO_FIX
cd TMP_REPO_FIX
git filter-branch --env-filter '
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 TMP_REPO_FIX/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment