显然,可以使用以下gitconfig
设置来强制Git用户为每个新存储库添加电子邮件地址:
git config --global user.email "(none)"
git config --global user.useConfigOnly true
我已经做了。我的gitconfig -l
输出(被截断):
core.symlinks=true
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
diff.astextplain.textconv=astextplain
rebase.autosquash=true
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.required=true
filter.lfs.process=git-lfs filter-process
credential.helper=manager
core.autocrlf=true
core.eol=native
user.name=David Wright
user.email=(none)
user.useconfigonly=true
但是它似乎没有用。我无需设置电子邮件地址即可提交。提交中列出的电子邮件地址(很奇怪)为“(无)”。
我正在使用git version 2.13.0.windows.1
。
我想这样做是因为我在同一台计算机上使用了两个不同的帐户。我可以在ssh-config
文件中应用不同的ssh-key达到类似的设置:
# github account
Host github.com
Port 22
HostName github.com
User git
IdentityFile <file>
但是显然git本身没有这种可能性。
无论如何,我希望能够强制我必须为每个存储库设置一个用户电子邮件地址,并且我希望这成为我的全局gitconfig的一部分。我知道可以使用预提交的挂钩执行此操作,但是据我所知,克隆之后需要将此挂钩复制到每个存储库中,这不是我想要的。
该的文件git config
解释:
user.useConfigOnly
指示Git避免尝试猜测
user.email
和的默认值user.name
,而是仅从配置中检索值。例如,如果您有多个电子邮件地址,并且希望为每个存储库使用不同的电子邮件地址,则true
在全局配置中将此配置选项设置为,同时加上名称,Git将提示您设置电子邮件,然后进行新的提交在新克隆的存储库中。默认为false
。
在未安装类Unix的系统(Linux,macOS等)上,如果user.email
未设置Git,则Git尝试通过将OS用户名@
和主机名连接起来生成电子邮件地址。
通过设置user.useConfigOnly
为true
这种行为,可以抑制行为,并且Git仅使用user.email
它在配置文件中找到的值(如果有)。
由于您已配置(none)
为user.email
,因此Git会将其用作提交者的电子邮件地址。
使用git config --global --unset user.email
删除它,Git将开始要求您user.email
为每个未设置的存储库(新的或现有的)输入电子邮件地址(或至少会抱怨未设置)user.email
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句