本文介绍了我可以配置git以便不猜测user.email的配置设置吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

On my system I don't have the user.email git configuration value set at the global level, on purpose. Instead, I configure it individually in each sandbox. This is because I need to use different e-mail addresses for different projects.

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

Unfortunately I sometimes forget to configure the value when I create a new sandbox. In those cases, git just "guesses" a value based on information it gets from the environment. That leads to various problems, for example commits are not attributed to me on github, and I won't have much luck getting those commits with @localhost e-mail addresses attributed to me retroactively.

当我尝试在未配置本地或全局user.email值的情况下提交时,是否可以将git配置为出错而不是猜测?

Is there a way to configure git to error out instead of guessing when I try to commit without a local or global user.email value configured?

推荐答案

现在有一个配置选项.

There is a config option for that now.

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

Instruct Git to avoid trying to guess defaults for user.email and user.name, and instead retrieve the values only from the configuration.

因此只需将其设置为true:

So just set this to true like this:

git config --global user.useConfigOnly true

下一次,当您尝试在没有显式设置user.email和user.name的情况下进行提交时,您将收到错误消息.

And next time when you try to make a commit without user.email and user.name explicitly set you will get an error.

$ 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

这篇关于我可以配置git以便不猜测user.email的配置设置吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 05:50