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
相关推荐
切糕师学AI1 小时前
如何查看已合并到 master 分支的所有分支?Git 分支清理指南
大数据·git·elasticsearch
磐时信息技术1 小时前
SASETalk | 当智能驾驶驶入未知场景:谈谈关于SOTIF、AI安全与工程落地的思考
人工智能·安全·预期功能安全·sotif
Chengbei112 小时前
SRC报告成稿 Skill(SRC/0day 提交稿、分层验证门、Step 式 PoC、截图铁律)
网络·人工智能·安全·web安全·自动化·系统安全
2601_966377132 小时前
云上系统零改造过密评|数达安全发布通关四件套
网络·安全
每天题库3 小时前
交安C证报考条件有哪些?公路水运安全员C证报名时间及考试科目
学习·安全·考试·题库·考证
sbjdhjd3 小时前
PHP eval 型 RCE:flag 正则过滤与通配符绕过实操 | 01
安全·web安全·网络安全·开源·系统安全·php·网络攻击模型
科技小登4 小时前
重大活动安全保障方案怎么选?重保服务、攻防演练、应急响应与安全意识培训实战与边界
数据库·人工智能·安全
七牛开发者4 小时前
拆解 dsh:Session 的事件溯源与状态重建
javascript·github·agent
数据知道4 小时前
静态分析入门——PE 结构、字符串、导入表快速定性
网络·安全·web安全·网络安全