How to change the commit author for one specific commit?

后端 未结 19 1799
没有蜡笔的小新
没有蜡笔的小新 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:46

    Find a way that can change user quickly and has no side effect to others commits.

    Simple and clear way:

    git config user.name "New User"
    git config user.email "newuser@gmail.com"
    
    git log
    git rebase -i 1f1357
    # change the word 'pick' to 'edit', save and exit
    
    git commit --amend --reset-author --no-edit
    git rebase --continue
    
    git push --force-with-lease
    

    detailed operations

    • show commit logs and find out the commit id that ahead of your commit which you want to change:
    git log
    
    • git rebase start from the chosed commit id to the recent reversely:
    git config user.name "New User"
    git config user.email "newuser@gmail.com"
    git rebase -i 1f1357
    
    # change word pick to edit, save and exit
    edit 809b8f7 change code order 
    pick 9baaae5 add prometheus monitor kubernetes
    edit 5d726c3 fix liquid escape issue   
    edit 3a5f98f update tags
    pick 816e21c add prometheus monitor kubernetes
    
    • rebase will Stopped at next commit id, output:
    Stopped at 809b8f7...  change code order 
    You can amend the commit now, with
      git commit --amend 
    
    Once you are satisfied with your changes, run
    
      git rebase --continue
    
    • comfirm and continue your rebase untill it successfully to refs/heads/master.
    # each continue will show you an amend message
    # use git commit --amend --reset-author --no-edit to comfirm
    # use git rebase --skip to skip
    git commit --amend --reset-author --no-edit
    git rebase --continue
    git commit --amend --reset-author --no-edit
    ...
    git rebase --continue
    Successfully rebased and updated refs/heads/master.
    
    • git push to update
    git push --force-with-lease
    

提交回复
热议问题