Lon*_*ner 6 git configuration git-commit
我没有故意进行任何全局user.email或全局user.name设置。
我喜欢使用git config user.email和git config user.name命令为每个 repo 设置我的 user.email 和 user.name 。
在带有 git 版本 2.17.0 的 macOS 上,如果我忘记在 Mac 上设置user.email或user.name获取 repo,当我运行时,git commit我会收到此错误:
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'lone@mymac.(none)')
Run Code Online (Sandbox Code Playgroud)
这很好,因为它提醒我需要为我的 repo设置user.email和user.name配置。
但是在我使用 git 版本 2.11.0 的 Debian 系统上,如果我忘记设置user.email或user.name用于存储库,当我运行git commit它时会以Lone Learner <lone@mydeb>作者的身份提交更改。我猜它会自动检测user.name到/etc/passwd并自动检测user.email为<user>@<host>.
我想在 Debian 或任何使用 Git 的系统上禁用user.name和自动检测user.email。如果我没有明确设置,user.name或者user.email我希望 Git 以上面 Mac 示例中所示的失败方式或以其他方式失败。无论如何,是否可以使用~/.gitconfig或其他方式实现这一目标?
从 Git 2.8 开始,使用:
git config --global user.useConfigOnly true
Run Code Online (Sandbox Code Playgroud)
这将避免在您的 Debian 环境中进行“自动检测”。
请参阅“如果未设置用户电子邮件,我如何进行 git 块提交? ”。