Skip to content

Instantly share code, notes, and snippets.

@lhns
Last active May 29, 2019 19:38
Show Gist options
  • Select an option

  • Save lhns/ffd07ebe148cdd1562ecfffdbf205fd3 to your computer and use it in GitHub Desktop.

Select an option

Save lhns/ffd07ebe148cdd1562ecfffdbf205fd3 to your computer and use it in GitHub Desktop.
Change author and committer of git commits
#!/bin/sh
# https://help.github.com/en/articles/changing-author-info
# https://stackoverflow.com/questions/750172/how-to-change-the-author-and-committer-name-and-e-mail-of-multiple-commits-in-gi
git clone --bare https://github.com/user/repo.git
cd repo.git
git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.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
git update-ref -d refs/original/refs/heads/master
rm -Rf refs/original
#git log --pretty=format:"[%h] %cd - Committer: %cn (%ce), Author: %an (%ae)"
git push --force --tags origin 'refs/heads/*'
cd ..
rm -rf repo.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment