【问题标题】:How do I prevent Git from auto-detecting user.email?如何防止 Git 自动检测 user.email?
【发布时间】:2018-07-08 07:14:24
【问题描述】:

我没有故意设置任何全局 user.email 或全局 user.name

我喜欢使用 git config user.emailgit config user.name 命令为每个 repo 设置我的 user.email 和 user.name。

在带有 git 版本 2.17.0 的 macOS 上,如果我忘记在我的 Mac 上为 repo 设置 user.emailuser.name,当我运行 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)')

这很好,因为它提醒我需要为我的 repo 设置 user.emailuser.name 配置。

但是在我的带有 git 版本 2.11.0 的 Debian 系统上,如果我忘记为 repo 设置 user.emailuser.name,当我运行 git commit 时,它会以 Lone Learner <lone@mydeb> 作为作者提交更改。我猜它会从/etc/passwd 自动检测user.name 并自动将user.email 检测为<user>@<host>

我想在 Debian 或任何启用了 Git 的系统上禁用对 user.nameuser.email 的自动检测。如果我没有明确设置user.nameuser.email,我希望Git 以上面Mac 示例中所示的失败方式或以其他方式失败。无论如何使用~/.gitconfig 或其他方式来实现这一点?

【问题讨论】:

标签: git configuration git-commit


【解决方案1】:

从 Git 2.8 开始,使用:

git config --global user.useConfigOnly true

这将避免在您的 Debian 环境中进行“自动检测”。
在“How do I make git block commits if user email isn't set?”查看更多信息。

【讨论】:

    猜你喜欢
    • 2011-07-11
    • 2011-07-13
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多