How to change the author and committer name and e-mail of multiple commits in Git?

后端 未结 30 3133
野性不改
野性不改 2020-11-21 04:50

I was writing a simple script in the school computer, and committing the changes to Git (in a repo that was in my pendrive, cloned from my computer at home). After several c

30条回答
  •  花落未央
    2020-11-21 05:05

    A single command 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
    exec git commit --amend --author 'Author Name ' --no-edit
    pick abb60f9 add new feature
    exec git commit --amend --author 'Author Name ' --no-edit
    pick dc18f70 bugfix
    exec git commit --amend --author 'Author Name ' --no-edit
    

    You can then still modify some lines to see where you want to change the author. This gives you a nice middle ground between automation and control: you see the steps that will run, and once you save everything will be applied at once.

提交回复
热议问题