git 批量修改Git Commit记录里的用户名和邮箱

文摘 Linux 2020-04-21 阅读:6210
  • 复制以下代码,保存为git_email.sh
#!/bin/sh

git filter-branch --env-filter '

OLD_EMAIL="旧邮箱地址"
CORRECT_NAME="新用户名"
CORRECT_EMAIL="新邮箱地址"

if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$CORRECT_NAME"
    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$CORRECT_NAME"
    export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' -f --tag-name-filter cat -- --branches --tags
  • 执行git_email.sh
./git_email.sh
  • 通过git log查看是否已修改完毕
git log
  • 同步远程仓库
git push origin --force --all

附件下载:
git_email.sh.txt

0条评论

© 2024 芯缘异码. Powered by Typecho