解決 Gitee 中 git push 因郵箱隱私設置導致的失敗問題
在使用 Git 向 Gitee 遠程倉庫推送代碼時,可能會遇到因郵箱隱私設置引發的 git push
失敗情況。最近我就碰到了,現在把問題現象、原因和解決方法分享出來。
一、錯誤現象
執行 git push -u origin "master"
命令后,終端輸出類似如下內容:
Enumerating objects: 12, done.
Counting objects: 100% (12/12), done.
Delta compression using up to 16 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (12/12), 953 bytes | 476.00 KiB/s, done.
Total 12 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
remote: error: GE007: your push would publish a private email address.
remote: You can make the email public or disable this protection by visiting:
remote: https://gitee.com/profile/emails
remote: error: hook declined to update refs/heads/master
To https://gitee.com/xiaobin111/git_wh_test.git! [remote rejected] master -> master (hook declined)
error: failed to push some refs to 'https://gitexxxxxxxgit_wh_test.git'
從提示能看出,推送操作被拒絕,原因是會暴露私人郵箱地址。
二、原因分析
Gitee 為了保護用戶隱私,若用戶在注冊賬戶時勾選了“不公開我的郵箱地址”選項,當執行 git push
等可能涉及郵箱信息的操作時,Gitee 會因為保護隱私而阻止推送,從而導致失敗。
三、解決方法
要解決這個問題,需要調整 Gitee 賬戶的郵箱隱私設置,具體步驟如下:
-
登錄 Gitee 賬戶,進入個人設置頁面。
-
在左側菜單欄中找到【郵箱管理】選項并點擊進入。
-
在“我的郵箱地址”區域,找到【不公開我的郵箱地址】選項,取消勾選該選項,如圖所示
: -
設置完成后,再次執行
git push
命令,就可以成功將代碼推送到 Gitee 遠程倉庫了。
總結
當在 Gitee 上遇到因郵箱隱私設置導致的 git push
失敗時,只需進入 Gitee 賬戶的郵箱管理頁面,取消“不公開我的郵箱地址”的勾選,就能順利解決問題,繼續進行代碼的推送工作。