Skip to content

Instantly share code, notes, and snippets.

@glhrmv
Last active October 16, 2019 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glhrmv/ddb3767459126cca60e25c5f3fa91621 to your computer and use it in GitHub Desktop.
Save glhrmv/ddb3767459126cca60e25c5f3fa91621 to your computer and use it in GitHub Desktop.
Change commit author & email in all commits of a repository
#!/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
@glhrmv
Copy link
Author

glhrmv commented Oct 16, 2019

Usage

Make the script an executable with

chmod +x update_commit_email.sh

Run it with

./update_commit_email.sh <github username> <github repo name>

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment