How to amend several commits in Git to change author

前端 未结 6 1003
逝去的感伤
逝去的感伤 2020-11-28 17:14

I have made a series of commits in Git and I realise now that I forgot to set my user name and user email properties correctly (new machine). I have not yet pushed these co

6条回答
  •  無奈伤痛
    2020-11-28 17:50

    To change the author only for the last commit:

    git commit --amend --author 'Author Name ' --no-edit
    

    Suppose you only want to change the author for the last N commits:

    git rebase -i HEAD~4 -x "git commit --amend --author 'Author Name ' --no-edit"
    

    NOTES

    • the --no-edit flag makes sure the git commit --amend doesn't ask an extra confirmation
    • when you use git rebase -i, you can manually select the commits where to change the author,

    the file you edit will look like this:

    pick 897fe9e simplify code a little
    pick abb60f9 add new feature
    exec git commit --amend --author 'Author Name ' --no-edit
    pick dc18f70 bugfix
    

提交回复
热议问题