How to change the commit author for one specific commit?

后端 未结 19 1861
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 05:15

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

19条回答
  •  [愿得一人]
    2020-11-22 05:54

    Interactive rebase off of a point earlier in the history than the commit you need to modify (git rebase -i ). 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 " --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 "
    6. Then git rebase --continue
    7. It would pause again at D
    8. Then you would git commit --amend --author="Author Name " again
    9. git rebase --continue
    10. The rebase would complete.
    11. Use git push -f to update your origin with the updated commits.

提交回复
热议问题