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

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

    I want to add my Example too. I want to create a bash_function with given parameter.

    this works in mint-linux-17.3

    # $1 => email to change, $2 => new_name, $3 => new E-Mail
    
    function git_change_user_config_for_commit {
    
     # defaults
     WRONG_EMAIL=${1:-"you_wrong_mail@hello.world"}
     NEW_NAME=${2:-"your name"}
     NEW_EMAIL=${3:-"new_mail@hello.world"}
    
     git filter-branch -f --env-filter "
      if [ \$GIT_COMMITTER_EMAIL = '$WRONG_EMAIL' ]; then
        export GIT_COMMITTER_NAME='$NEW_NAME'
        export GIT_COMMITTER_EMAIL='$NEW_EMAIL'
      fi
      if [ \$GIT_AUTHOR_EMAIL = '$WRONG_EMAIL' ]; then
        export GIT_AUTHOR_NAME='$NEW_NAME'
        export GIT_AUTHOR_EMAIL='$NEW_EMAIL'
      fi
     " --tag-name-filter cat -- --branches --tags;
    }
    

提交回复
热议问题