GitHub报错:error: GH007: Your push would publish a private email address.

2

在GitHub的隐私设置中勾选了Block command line pushes that expose my email后,再次提交的Git项目中如果提交暴露私人邮箱地址的commit时会报错

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
To github.com:xxxx/xxxx.git
 ! [remote rejected] master -> master (push declined due to email privacy restrictions)
error: failed to push some refs to '[email protected]:xxxx/xxxx.git'

网上搜索了一下,大多提供的解决方案都是取消Keep my email address private,这显然违背了GitHub提供这个功能的初衷,并且会公开你的私人邮箱
真正的解决方案应该是修改Git中的邮箱地址为GitHub提供的匿名邮箱才对

# 修改全局邮件地址
git config --global user.email "用户名@users.noreply.github.com"
git config user.email "用户名@users.noreply.github.com"
# 重置 commit 的作者信息
git commit --amend --reset-author
# 再次提交
git push

共 2 条评论

  1. 回复

    赞,感谢!

  2. 回复

    测试可行,感谢!

发表评论

您的邮箱不会公开,当您的评论有新的回复时,会通过您填写的邮箱向您发送评论内容。 必填字段 *

为何看不到我发布的评论?

正在提交, 请稍候...