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
相关推荐
Beyond欣13 分钟前
RepoReporter 仿照`TortoiseSVN`项目监视器,能够同时支持SVN和Git仓库
git·svn
燕雀安知鸿鹄之志哉.23 分钟前
ctfshow WEB web5
安全·web安全·网络安全·系统安全
uhakadotcom2 小时前
轻松构建大型语言模型应用:Flowise入门指南
前端·面试·github
深度学习机器2 小时前
Docling:统一的多文档解析框架 支持多种文档类型的处理与转换
人工智能·github·产品
深度学习机器2 小时前
MCP原理解析与效果实测|附实用MCP推荐
微服务·架构·github
dora2 小时前
Android数据缓存框架 - 内存缓存与数据的发布订阅
android·开源·github
Sinokap2 小时前
Let’s Encrypt 宣布推出短期证书与 IP 地址支持,推动 Web 安全迈向新高度
前端·tcp/ip·安全·ocr
ianozo2 小时前
[GXYCTF2019]禁止套娃1 [GitHack] [无参数RCE]
git
傲娇的萌2 小时前
Nextjs项目部署GithubPages
github
屎派克3 小时前
物理安全——问答
安全