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

后端 未结 30 3048
野性不改
野性不改 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:07

    I should point out that if the only problem is that the author/email is different from your usual, this is not a problem. The correct fix is to create a file called .mailmap at the base of the directory with lines like

    Name you want  Name you don't want 
    

    And from then on, commands like git shortlog will consider those two names to be the same (unless you specifically tell them not to). See http://schacon.github.com/git/git-shortlog.html for more information.

    This has the advantage of all the other solutions here in that you don't have to rewrite history, which can cause problems if you have an upstream, and is always a good way to accidentally lose data.

    Of course, if you committed something as yourself and it should really be someone else, and you don't mind rewriting history at this point, changing the commit author is probably a good idea for attribution purposes (in which case I direct you to my other answer here).

提交回复
热议问题