gitconfig文件中`[github]`和`[github "user"]`有什么区别?

3

我在gitconfig中有以下两个块,其中<placeholders>已用实际信息替换:

[github]
  user = <name>
  token = <token>
  email = <email address>
[github "user"]
  user = <name>
  token = <token>
  email = <email address>

两个元素都包含相同的3个值,我认为这种重复是不必要的,但它们有什么区别,我应该删除哪个?目前没有出现任何问题。

此外,我还有以下代码块:

[user]
  name = <name>
  email = <email address>

同样的姓名和电子邮件地址。

更新: 运行git config --list命令会显示以下值:

github.user
github.token
github.email

以及

github.user.user
github.user.token
github.user.email

我觉得这里有些不对劲,所以我从文件中删除了整个[github "user"]块。目前似乎没有出现任何问题。

2个回答

2
据我所知,该语法意味着您拥有一个github部分和一个github "user"子部分(请参见语法下的示例)。这意味着您可以访问github,并且您还可以像使用--list一样访问github.user。这样您就可以存储不同的值。由于您的值相同,因此您应该能够删除[github "user"]而不会破坏任何内容,正如您所看到的那样。

0
注意:要小心 git config 子节:最近更新的“git config”破坏了子节中变量的更新,这已在 Git 2.19(2018 年第三季度)得到修正。
这说明了节和子节之间的区别。

请查看提交 bff7df7, 提交 2d84f13 (2018年8月8日),以及提交 999d902 (2018年8月1日) ,作者为Stefan Beller (stefanbeller)
(由Junio C Hamano -- gitster --合并于提交 2a2c18f,2018年8月20日)

config: fix case sensitive subsection names on writing

A user reported a submodule issue regarding a section mix-up, but it could be boiled down to the following test case:

$ git init test  && cd test
$ git config foo."Bar".key test
$ git config foo."bar".key test
$ tail -n 3 .git/config
[foo "Bar"]
      key = test
      key = test

Sub sections are case sensitive and we have a test for correctly reading them.
However we do not have a test for writing out config correctly with case sensitive subsection names, which is why this went unnoticed in 6ae996f (git_config_set: make use of the config parser's event stream, 2018-04-09, Git 2.18)

Unfortunately we have to make a distinction between old style configuration that looks like:

[foo.Bar]
      key = test

and the new quoted style as seen above.

The old style is documented as case-agnostic, hence we need to keep 'strncasecmp'; although the resulting setting for the old style config differs from the configuration.


请确保使用Git 2.19(如上所示),或者至少使用Git 2.13或更高版本。

未记录的是git -c曾经将变量名转换为小写:

vonc@bvonc MINGW64 ~
$ git version
git version 2.12.0.windows.1

vonc@bvonc MINGW64 ~
$ git -c VAR=c config -l|grep var
var=c

这可能是在区分大小写的操作系统上的一个问题(请参见下面的url大小写)

Git 2.13(Q2 2017)中已经修复了此问题,这提供了另一个例子来说明节和子节之间的区别。

请查看 提交 1274a15提交 ee98df3(2017年2月23日),作者为 Junio C Hamano (gitster)
(由Junio C Hamano -- gitster --合并于提交 2f54451,2017年3月10日)

config:在git_config_parse_parameter()中使用git_config_parse_key()

从命令行传递的配置变量的一次性赋值历史上一直很松散,允许任何内容通过。

它还将变量名称中的所有内容转换为小写字母, 即使是三级的<section>.<subsection>.<variable>名称中的部分也必须以区分大小写的方式处理。

设置URL时,操作系统不管怎样都会考虑大小写问题,在下面是一个三级<section>.<subsection>.<variable>名称的示例:

vonc@bvonc MINGW64 ~
$ git -c url."https://myserver/GitLab".insteadOf=git@myserver.org/GitLab config -l|grep -i Gitlab
url.https://myserver.org/gitlab.insteadof=git@myserver.org/GitLab

如果您的私有 Git 存储库服务器 URL 不完全为小写,则该命令将不起作用。
虽然 url 的方案可能不区分大小写, 以及域名, 但 url 的其余部分(这里是 /GitLab 部分)可能区分大小写


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接