前置条件

  1. windows系统、github设置隐私邮箱

  2. 使用Github给的邮箱替换了原有的邮箱,命令如下:

    1
    2
    
    git config --global user.name  "xxx"
    git config --global user.email "xxx"
    
  3. 用旧的邮箱进行了commit

过程

  1. 在替换为新的邮箱之后使用 git push 命令提交代码被拒绝,返回以下提示:

    1
    2
    3
    4
    
        Can't finish GitHub sharing process
        Successfully created project 'xxx' on GitHub, but initial push failed:
        remote: error: GH007: Your push would publish a private email address.
        failed to push some refs to 'xxx'
    
  2. 使用 git config --list 查看邮箱是否正确

    1
    2
    
    user.name=xxx
    user.email=xxx
    

    发现没有问题,和修改后的邮箱一直

  3. 经过回溯之后,发现在修改邮箱之前,使用原来的邮箱进行了 commit,但是没有 push。因此commit的内容用的还是原来的邮箱,导致push时报错

解决方法

  1. 使用 git reset 命令回退版本到 commit 之前
  2. 重新 commit 和 push,push 成功