Reset Github Commit Author

«  Tarjan's strongly connected components algorithm
SED Command  »

Sometimes, we might set commit author wrong. And I’ve met this issue recently. I miss typed git config --global user.mail when I actually want to set user.email.

For fixing it, I searched some info online, and I’d like to sum up them at here.

Reset ALL commits Author

Here is a nice blog for it: https://mhagemann.medium.com/how-to-change-the-user-for-all-your-git-commits-ffefbacf2652. Feel free to check it if you are interested in.

$ git filter-branch --env-filter '
OLD_EMAIL="old@example.com"
NEW_NAME="new name"
NEW_EMAIL="new@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
  export GIT_COMMITTER_NAME="$NEW_NAME"
  export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
  export GIT_AUTHOR_NAME="$NEW_NAME"
  export GIT_AUTHOR_EMAIL="$NEW_EMAIL"
fi'

# refresh all history
$ git push origin --force --all

Reset One Specific Commit

  • If this commit is on the top, we can solve it by:
# Update `git config` first, then run ⬇️
$ git commit --amend --reset-author
  • If this commit is on the middle, try rebase to solve it:
$ git rebase -i -p <some HEAD before all of your bad commits>
$ git commit --amend --author "New Author Name <email@address.com>"
$ git rebase --continue

Reference

Published on 08 May 2021 Find me on Facebook, Twitter!

«  Tarjan's strongly connected components algorithm
SED Command  »

Comments

    Join the discussion for this article at here . Our comments is using Github Issues. All of posted comments will display at this page instantly.