Skip to content

Instantly share code, notes, and snippets.

@loivis
Last active June 9, 2022 19:21
Show Gist options
  • Save loivis/597110293fe360dd3b53837f413271db to your computer and use it in GitHub Desktop.
Save loivis/597110293fe360dd3b53837f413271db to your computer and use it in GitHub Desktop.
reset commit user/author in git history
reset commit user(author) in git history

reference: http://stackoverflow.com/a/750191

be careful if you have a multi-user repository - this will change ALL commits to have the same (new) author and committer.

#!/bin/sh

git filter-branch -f --env-filter "
    GIT_AUTHOR_NAME='loivis'
    GIT_AUTHOR_EMAIL='[email protected]'
    GIT_COMMITTER_NAME='loivis'
    GIT_COMMITTER_EMAIL='[email protected]'
  " HEAD

for all commits

reference: https://help.github.com/articles/changing-author-info/

  1. update and run script
#!/bin/sh

git filter-branch --env-filter '

OLD_EMAIL="[email protected]"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="[email protected]"

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/*'
  1. review git history and push changes
git push --force --tags origin 'refs/heads/*'

for the last commit

git config user.name "your name"
git config user.email "your email"
git commit --amend --reset-author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment