【发布时间】:2018-07-08 07:14:24
【问题描述】:
我没有故意设置任何全局 user.email 或全局 user.name。
我喜欢使用 git config user.email 和 git config user.name 命令为每个 repo 设置我的 user.email 和 user.name。
在带有 git 版本 2.17.0 的 macOS 上,如果我忘记在我的 Mac 上为 repo 设置 user.email 或 user.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.email 和 user.name 配置。
但是在我的带有 git 版本 2.11.0 的 Debian 系统上,如果我忘记为 repo 设置 user.email 或 user.name,当我运行 git commit 时,它会以 Lone Learner <lone@mydeb> 作为作者提交更改。我猜它会从/etc/passwd 自动检测user.name 并自动将user.email 检测为<user>@<host>。
我想在 Debian 或任何启用了 Git 的系统上禁用对 user.name 和 user.email 的自动检测。如果我没有明确设置user.name 或user.email,我希望Git 以上面Mac 示例中所示的失败方式或以其他方式失败。无论如何使用~/.gitconfig 或其他方式来实现这一点?
【问题讨论】:
-
@torek 感谢您分享副本。在发布此问题之前,我确实尝试搜索有关此主题的现有问题,但我尝试的搜索词(例如:git prevent auto detect user.email)没有帮助。
-
嗯,重复并不坏,有时(如本例)甚至是好的。请参阅此处的元讨论:meta.stackexchange.com/questions/10841/… 我不确定是否应该关闭它,更不用说选择哪个作为骗子了... :-)
标签: git configuration git-commit