Last active
October 16, 2019 13:20
-
-
Save glhrmv/ddb3767459126cca60e25c5f3fa91621 to your computer and use it in GitHub Desktop.
Change commit author & email in all commits of a repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 <repo owner> <repo name>" | |
fi | |
REPO_OWNER="$1" | |
REPO_NAME="$2.git" | |
# Clone the repo | |
git clone --bare "https://github.com/$REPO_OWNER/$REPO_NAME" | |
# Change to the raw repo directory | |
cd $REPO_NAME | |
# Taken from https://help.github.com/en/articles/changing-author-info | |
git filter-branch --env-filter ' | |
OLD_EMAIL="old.commit.email@email.com" | |
CORRECT_NAME="Correct author name" | |
CORRECT_EMAIL="old.commit.email@email.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 | |
# Push changes to remote | |
git push --force --tags origin 'refs/heads/*' | |
# Delete the raw repo directory | |
cd .. | |
rm -rf $REPO_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
Make the script an executable with
Run it with
Configuring
You will have to directly modify the script contents, lines 19-21, with the correct details you need.
Notes
It's a very crude script, some user friendliness is appreciated. Feel free to improve upon it (and share it here).