批量修改历史commit的用户名user.name邮箱user.email

配置当前的用户名邮箱可以当前项目配置或者全局配置。

仅当前项目配置:

git config user.name 'your-user-name'
git config user.email 'your-user-email'

全局配置:

git config --global user.name 'your-user-name'
git config --global user.email 'your-user-email'

新建shell脚本 change-email-name.sh 内容如下:

#!/bin/sh

git filter-branch -f --env-filter '

OLD_EMAIL="your-old-email"
NEW_NAME="your-new-name"
NEW_EMAIL="your-new-email"

if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$NEW_NAME"
    export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$NEW_NAME"
    export GIT_AUTHOR_EMAIL="$NEW_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
将脚本放到项目根目录下,执行脚本:
./change-email-name.sh

如果执行失败,执行以下代码后再执行脚本:

git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch Rakefile' HEAD

然后强行覆盖仓库

git push origin --force --all

 

 

 

 

 

posted @ 2018-11-30 17:13  SKILL·NULL  阅读(410)  评论(0编辑  收藏  举报