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
相关推荐
jenchoi4134 分钟前
【2025-11-23】软件供应链安全日报:最新漏洞预警与投毒预警情报汇总
网络·数据库·安全·web安全·网络安全
whysqwhw23 分钟前
BaseObject 及其子类的完整继承关系 ASCII 树
github
独行soc1 小时前
2025年渗透测试面试题总结-258(题目+回答)
网络·python·安全·web安全·渗透测试·安全狮
r***d8652 小时前
GitHub星标15万+的Docker项目,使用指南
docker·容器·github
AI绘画小332 小时前
网络安全(黑客技术)—2025自学手册
网络·安全·web安全·网络安全·渗透测试
合才科技3 小时前
【要闻周报】网络安全与数据合规 11-21
安全·web安全
sulikey3 小时前
从入门到精通:如何自己编写高质量的 .gitignore(面向工程实践)
git·gitee·编辑器·gitlab·github·gitignore·gitattributes
散峰而望3 小时前
C++数组(一)(算法竞赛)
c语言·开发语言·c++·算法·github
SelectDB5 小时前
压缩率提升 48%,详解 Apache Doris 存储压缩优化之道|Deep Dive
数据库·开源·github
❀͜͡傀儡师6 小时前
docker部署orion-ops一站式运维管理平台
运维·docker·github