
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.
-
Open Terminal.
-
Change the current working directory to your local project.
-
Checkout the commit we are trying to modify.
git checkout 03f482d6- Make the author change.
git commit --amend --author "New Author Name <New Author Email>"-
Now we have a new commit with hash assumed to be 42627abe.
-
Checkout the original branch. For example if the original branch was master.
git checkout master- Replace the old commit with the new one locally.
git replace 03f482d6 42627abe- Rewrite all future commits based on the replacement.
git filter-branch -- --all- Remove the replacement for cleanliness.
git replace -d 03f482d6- Push the new history (only use --force if the below fails, and only after sanity checking with git log and/or git diff).
git push --force-with-leaseNote: Instead of 7-9 you can just rebase onto new commit:
git rebase -i 42627abeCREDITS
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.