Skip to content

Instantly share code, notes, and snippets.

@albertodebortoli
Last active November 10, 2023 08:41
Show Gist options
  • Save albertodebortoli/b2a6c3ebe82d9c13fe77 to your computer and use it in GitHub Desktop.
Save albertodebortoli/b2a6c3ebe82d9c13fe77 to your computer and use it in GitHub Desktop.
Change the author of a commit in Git

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

@renoirtech
Copy link

Thank you so much!

@Sazeidya
Copy link

Thank you very much, that saved me! Committed a PR with wrong author and e-mail. With this I could fix it!

@kiswayODG
Copy link

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment