Change commit author name & email
by Amend
, then replacing old-commit with new-one
:
$ git checkout <commit-hash> # checkout to the commit need to modify
$ git commit --amend --author "name <[email protected]>" # change the author name and email
$ git replace <old-commit-hash> <new-commit-hash> # replace the old commit by new one
$ git filter-branch -- --all # rewrite all futures commits based on the replacement
$ git replace -d <old-commit-hash> # remove the replacement for cleanliness
$ git push -f origin HEAD # force push
Another way Rebasing
:
$ git rebase -i <good-commit-hash> # back to last good commit
# Editor would open, replace 'pick' with 'edit' before the commit want to change author
$ git commit --amend --author="author name <[email protected]>" # change the author name & email
# Save changes and exit the editor
$ git rebase --continue # finish the rebase