Using Interactive Rebase
git rebase -i -p <some HEAD before all of your bad commits>
Then mark all of your bad commits as "edit" in the rebase file, and when git asks you to amend each commit, do
git commit --amend --author "New Author Name <[email protected]>"
edit or just close the editor that opens, and then do
git rebase --continue
to continue the rebase.
You could skip opening the editor altogether here by appending --no-edit so that the command will be:
git commit --amend --author "New Author Name <[email protected]>" --no-edit && \
git rebase --continue
Single Commit
As some of the commenters have noted, if you just want to change the most recent commit, the rebase command is not necessary. Just do
git commit --amend --author "New Author Name <[email protected]>"
This will change the author to the name specified, but the committer will be set to your configured user in git config user.name and git config user.email. If you want to set the committer to something you specify, this will set both the author and the committer:
git -c user.name="New Author Name" -c [email protected] commit --amend --reset-author
Thank you so much!