Skip to content

Latest commit

 

History

History
80 lines (59 loc) · 1.69 KB

change-author-info.md

File metadata and controls

80 lines (59 loc) · 1.69 KB

Change author info retroactively

#unix #bash #git

Before pushing

  1. Fix your information in the Git configuration of the project:
git config user.name "Your Correct Name"
git config user.email "your-correct-email@example.com"
  1. Start rebase:
git rebase -i HEAD~1 # will bring up an editor
  1. In the editor, mark the commit as edit, then save and exit the editor.

  2. Do an amend that resets the author now that your information is updated:

git commit --amend --reset-author
  1. Finish the rebase:
git rebase --continue

After pushing

Open up a terminal:

git clone --bare https://github.com/<user>/<repo>.git
cd <repo>.git
nano git-author-rewrite.sh # create new script

Save the script like this:

#!/bin/sh

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

Back in the terminal:

chmod u+x git-author-rewrite.sh # make script executable
./git-author-rewrite.sh # run
git log # review Git history for errors
git push --force --tags origin 'refs/heads/*'
cd ..
rm -rf <repo>.git

Sources