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

后端 未结 30 3051
野性不改
野性不改 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 04:54

    In the case where just the top few commits have bad authors, you can do this all inside git rebase -i using the exec command and the --amend commit, as follows:

    git rebase -i HEAD~6 # as required
    

    which presents you with the editable list of commits:

    pick abcd Someone else's commit
    pick defg my bad commit 1
    pick 1234 my bad commit 2
    

    Then add exec ... --author="..." lines after all lines with bad authors:

    pick abcd Someone else's commit
    pick defg my bad commit 1
    exec git commit --amend --author="New Author Name " -C HEAD
    pick 1234 my bad commit 2
    exec git commit --amend --author="New Author Name " -C HEAD
    

    save and exit editor (to run).

    This solution may be longer to type than some others, but it's highly controllable - I know exactly what commits it hits.

    Thanks to @asmeurer for the inspiration.

提交回复
热议问题