How to change Author of a previous Git Commit.

PURPOSE

To change the Author of a previous commit in a Repository.

Many times you end up commiting and pushing changes to a repository from a different account than you originally intended to do. You can ignore that commit, and move on in life Or You can follow these steps below:

Assume for clarity of exposition that 03f482d6 is the commit whose author we are trying to replace, and 42627abe is the commit with the new author.
  1. Open Terminal.
  2. Change the current working directory to your local project.
  3. Checkout the commit we are trying to modify.
  1. Make the author change.
  1. Now we have a new commit with hash assumed to be 42627abe.
  2. Checkout the original branch. For example if the original branch was master.
  1. Replace the old commit with the new one locally.
  1. Rewrite all future commits based on the replacement.
  1. Remove the replacement for cleanliness.
  1. Push the new history (only use --force if the below fails, and only after sanity checking with git log and/or git diff).

Note: Instead of 7-9 you can just rebase onto new commit:

CREDITS

This article is from a StackOverflow Answer here I am adding it here to quickly reference it when I inevitably forget how to do it.

Thank the author. Fork this blog.


Tagged in git