我可以配置git,因此它不会猜测user.email配置设置吗?

Mar*_*age 10 git

在我的系统上,我没有user.email故意在全局级别设置git配置值.相反,我在每个沙箱中单独配置它.这是因为我需要为不同的项目使用不同的电子邮件地址.

不幸的是,我有时忘记在创建新沙箱时配置该值.在这些情况下,git只是根据从环境中获取的信息"猜测"一个值.这导致了各种各样的问题,例如提交不归因于我在github上,并且我不会有太多的运气来获得那些具有@localhost追溯归因于我的电子邮件地址的提交.

有没有办法配置git错误输出而不是猜测我何时尝试提交没有user.email配置本地或全局值?

Ser*_*i M 8

现在有一个配置选项.

user.useConfigOnly

指示Git避免尝试猜测user.email和user.name的默认值,而只是从配置中检索值.

所以只需将此设置为true,如下所示:

git config --global user.useConfigOnly true
Run Code Online (Sandbox Code Playgroud)

下次当您尝试在没有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: no email was given and auto-detection is disabled
Run Code Online (Sandbox Code Playgroud)