首先,用户认证与user.name
和user.email
Git配置没有关系。
其次,与旧答案“从Git中删除凭据”相比,最新的Git for Windows使用了Git Credential Manager (Git 2.9.2 => GCM 1.5.0)。
检查您的配置 (git config -l
), 看看是否已注册“manager
”(或者更近期的2020+:“manager-core
”)。
如果没有,请设置它:
git config --global credential.helper manager-core
自从2016年4月的v1.3.0版本以来,它就有了一个删除命令来清除凭据。
git credential-manager delete <url>
更新 2018 年:"delete
" 已弃用,请使用 reject
:
更新 2020 年:"reject
" 已弃用,请使用 erase
:
git credential-manager erase <url>
实际上,无论您使用哪个'xxx
'凭据管理器('xxx
'是git config credential.helper
的结果),您都可以执行以下操作:
printf "protocol=https\nhost=github.com" | git-credential-xxx erase
# Windows (2020-2021)
printf "protocol=https\nhost=github.com" | git-credential-manager-core erase
# Linux
printf "protocol=https\nhost=github.com" | git-credential-libsecret erase
# MacOs
printf "protocol=https\nhost=github.com" | git-credential-osxkeychain erase
这比玩弄您操作系统的凭据管理器要好。
在您的Git安装中,git-credential-xxx
可执行文件在usr/libexec/git-core
或(对于Windows)mingw64/libexec/git-core
中。
如在此提到的那样,在MacOS上,它应该已经在/usr/local/git/bin/
中。
如果git config credential-manager
返回store
,则Git使用“store
”模式,将凭据保存到磁盘上的纯文本文件中,并且它们永远不会过期。
type %USERPROFILE%\.git-credentials
我建议从配置中删除该凭据助手,因为它以明文形式存储凭据。
实际上,提问者Lord Rixuel 在评论中确认了这是一个本地Windows凭据管理器函数,无论是否使用Git,都可以自动提供凭据:
我看到“管理凭据”选项,出于好奇我点了进去,然后点击“Windows凭据”,在“通用凭据”下面有“git:github.com
”,我点击它,然后出现“删除”选项。我点击了删除。
当我执行 git push
时,它又要求我输入用户名和密码。这正是我想要注销时的效果。