Skip to content
Fix Code Error

How to change the commit author for one specific commit?

March 13, 2021 by Code Error
Posted By: Anonymous

I want to change the author of one specific commit in the history. It’s not the last commit.

I know about this question – How do I change the author of a commit in git?

But I am thinking about something, where I identify the commit by hash or short-hash.

Solution

Interactive rebase off of a point earlier in the history than the commit you need to modify (git rebase -i <earliercommit>). In the list of commits being rebased, change the text from pick to edit next to the hash of the one you want to modify. Then when git prompts you to change the commit, use this:

git commit --amend --author="Author Name <[email protected]>" --no-edit

For example, if your commit history is A-B-C-D-E-F with F as HEAD, and you want to change the author of C and D, then you would…

  1. Specify git rebase -i B (here is an example of what you will see after executing the git rebase -i B command)
    • if you need to edit A, use git rebase -i --root
  2. Change the lines for both C and D from pick to edit
  3. Exit the editor (for vim, this would be pressing Esc and then typing :wq).
  4. Once the rebase started, it would first pause at C
  5. You would git commit --amend --author="Author Name <[email protected]>"
  6. Then git rebase --continue
  7. It would pause again at D
  8. Then you would git commit --amend --author="Author Name <[email protected]>" again
  9. git rebase --continue
  10. The rebase would complete.
  11. Use git push -f to update your origin with the updated commits.
Answered By: Anonymous

Related Articles

  • Git workflow and rebase vs merge questions
  • Why do I have to "git push --set-upstream origin "?
  • How to cherry pick a range of commits and merge into another…
  • How can I merge two commits into one if I already started…
  • Git Using Remote Branch
  • Checkout another branch when there are uncommitted changes…
  • git pull while not in a git directory
  • How do I make a Git commit in the past?
  • What's the difference between HEAD^ and HEAD~ in Git?
  • How can I reconcile detached HEAD with master/origin?

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Running a command as Administrator using PowerShell?

Next Post:

The located assembly’s manifest definition does not match the assembly reference

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Get code errors & solutions at akashmittal.com
© 2022 Fix Code Error