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_EMAIL、CORRECT_NAME和CORRECT_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
相关推荐
砚凝霜7 小时前
【软考信息安全】第二十二章 Web服务器安全分析与增强——Apache与IIS
服务器·前端·安全
AI砖家7 小时前
安全进入 Agent Loop:2027 年 Coding Agent 的决胜点
数据库·安全·codex·vibecoding
wflynn8 小时前
GitHub 日榜趋势速报 | 2026-10-13
开源·github
himobrinehacken8 小时前
取模运算的汇编奥秘揭秘
c语言·安全
墨云安全9 小时前
内网资产无法暴露到公网,怎么做安全检测?2026 年内网渗透测试的落地路径
开发语言·安全·网络安全·渗透测试·php
2601_967212729 小时前
安全型电源轨道系统合规选型技术指标与行业技术路线分析
大数据·经验分享·安全
山东科恩光电9 小时前
安全地毯高灵敏感应机制与耐磨材质优势及多场所防护安装维护指南
安全
goehou10 小时前
Prompt 注入实战:直接注入、间接注入和四道防线(附测试样例)
安全·ai·llm·agent·prompt注入
m4Rk_11 小时前
【论文阅读】Agent 记忆机制(99):PrisMem——从整体分数搜索走向能力驱动的记忆自进化
论文阅读·人工智能·学习·开源·github
世岩清上12 小时前
工厂安全目视化标识不全该怎么整改?标准化落地全流程方案
人工智能·安全·工厂目视化·车间目视化·企业目视化·新建厂房目视化