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

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

    As docgnome mentioned, rewriting history is dangerous and will break other people's repositories.

    But if you really want to do that and you are in a bash environment (no problem in Linux, on Windows, you can use git bash, that is provided with the installation of git), use git filter-branch:

    git filter-branch --env-filter '
      if [ $GIT_AUTHOR_EMAIL = bad@email ];
        then GIT_AUTHOR_EMAIL=correct@email;
      fi;
    export GIT_AUTHOR_EMAIL'
    

    To speed things up, you can specify a range of revisions you want to rewrite:

    git filter-branch --env-filter '
      if [ $GIT_AUTHOR_EMAIL = bad@email ];
        then GIT_AUTHOR_EMAIL=correct@email;
      fi;
    export GIT_AUTHOR_EMAIL' HEAD~20..HEAD
    

提交回复
热议问题