git 批量更改提交者邮箱规避 GH007 private email address 问题

问题描述

有时我们在推送提交时,会看到如下报错

bash 复制代码
remote: error: GH007: Your push would publish a private email address.
remote: You can make your email public or disable this protection by visiting:
remote: http://github.com/settings/emails

这是因为我们将提交中的邮箱设为了私密。因此,需要快速将所有邮箱更改为GitHub提供的no-reply版本。

解决方案

更改以下代码中的OLD_EMAILCORRECT_NAMECORRECT_EMAIL,执行即可。

bash 复制代码
git filter-branch --env-filter '
OLD_EMAIL="欲匹配的提交者邮箱@123.com"
CORRECT_NAME="新的提交者名"
CORRECT_EMAIL="新的提交者邮箱@123.com"

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
' --tag-name-filter cat -- --branches --tags

结果类似下面的输出

bash 复制代码
WARNING: git-filter-branch has a glut of gotchas generating mangled history
         rewrites.  Hit Ctrl-C before proceeding to abort, then use an
         alternative filtering tool such as 'git filter-repo'
         (https://github.com/newren/git-filter-repo/) instead.  See the
         filter-branch manual page for more details; to squelch this warning,
         set FILTER_BRANCH_SQUELCH_WARNING=1.
Proceeding with filter-branch...

Rewrite xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (51/71) (1 seconds passed, remaining 0 predicted)  

接下来,还可选择使用force push强行同步到远端仓库。

bash 复制代码
git push --force
相关推荐
用户6210245309241 分钟前
React:当UI开发从「搬砖」变成「搭乐高」的魔法时刻!
github
用户3918384172111 小时前
Jupyter Notebook:不只是个笔记本,而是你的科学计算驾驶舱!
github
用户255581606901 小时前
Laravel实战指南:从工匠工具到现代PHP开发的艺术
github
用户082699822601 小时前
Docker革命:为什么你的下一个项目必须容器化?🚀
github
用户709991950831 小时前
从零开始认识Elasticsearch:不只是搜索引擎的分布式神器!
github
用户24961588305991 小时前
Express.js:让Node.js搞Web开发爽到飞起!(以及为啥你离不开它)
github
CC码码1 小时前
管理你的多个 Git 密钥(多平台多账号)
git·gitlab·github
CC码码1 小时前
管理你的多个 Git 密钥(单平台多账号)
git·gitlab·github
大卫小东(Sheldon)1 小时前
GIM 1.5发布了! 支持Windows系统了
git·ai·rust
云原生社区1 小时前
Fabric:为你的命令行安上 AI 管道
人工智能·开源·github