在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
赞,感谢!
测试可行,感谢!