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

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

    I adapted this solution which works by ingesting a simple author-conv-file (format is the same as one for git-cvsimport). It works by changing all users as defined in the author-conv-file across all branches.

    We used this in conjunction with cvs2git to migrate our repository from cvs to git.

    i.e. Sample author-conv-file

    john=John Doe 
    jill=Jill Doe 
    

    The script:

     #!/bin/bash
    
     export $authors_file=author-conv-file
    
     git filter-branch -f --env-filter '
    
     get_name () {
         grep "^$1=" "$authors_file" |
         sed "s/^.*=\(.*\) <.*>$/\1/"
     }
    
     get_email () {
         grep "^$1=" "$authors_file" |
         sed "s/^.*=.* <\(.*\)>$/\1/"
     }
    
     GIT_AUTHOR_NAME=$(get_name $GIT_COMMITTER_NAME) &&
         GIT_AUTHOR_EMAIL=$(get_email $GIT_COMMITTER_NAME) &&
         GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME &&
         GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL &&
         export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL &&
         export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
     ' -- --all
    

提交回复
热议问题