"includeif" 在 Git for Windows 上不能正常工作。

5

我最近升级到git版本2.33.1.windows.1
但是 includeif 看起来并没有起作用。
有其他人能否确认?我记不清我的先前 git 版本是什么。

我的配置如下:

.gitconfig

[user]
  name = crowne
  email = crowne@fakemail.com
[includeIf "gitdir:E:/work/**"]
  path = ~/.gitconfig_work

.gitconfig_work

[user]
    name = name.surname
    email = name.surname@work.com

我之所以升级是因为在 E:/work/ 的子目录嵌套超过一个目录时,includeif 不会递归生效。
自升级后,它似乎根本没有生效。
只有以下位置的条目会显示:>git config -l --show-origin
  • C:/Program Files/Git/etc/gitconfig
  • C:/Users/crowne/.gitconfig
我没有看到任何来自于以下位置的条目:
  • C:/Users/crowne/.gitconfig_work

1
尝试使用 [includeIf "gitdir/i:E:/work"](不区分大小写,无 **)。 - phd
我已经尝试过了,但还是没有解决问题。 - crowne
这对我来说不再是问题了,我目前使用的是git版本2.34.1.windows.1。然而,我现在也在一台新电脑上工作,我的工作包含路径现在是:[includeIf "gitdir/i:/work/"] path = ~/.gitconfig_work - crowne
2个回答

7

我尝试了git v2.35.1,对我来说,神奇的是在结尾删除**并仅保留单独的斜杠/。我还添加了/i选项以忽略大小写。

.gitconfig,对我有效

[user]
  name = crowne
  email = crowne@fakemail.com
[includeIf "gitdir/i:E:/work/"]
  path = ~/.gitconfig_work

无法工作 a)

[user]
  name = crowne
  email = crowne@fakemail.com
[includeIf "gitdir/i:E:/work/**"]
  path = ~/.gitconfig_work

无法工作 b)

[user]
  name = crowne
  email = crowne@fakemail.com
[includeIf "gitdir/i:E:/work"]
  path = ~/.gitconfig_work

2
在Ubuntu下出现了类似的问题,从Bionic(git v2.17)切换到Focal(git v2.25.1)后,我使用了[includeIf "gitdir:~/workspace/*"]并且在旧版本下运行正常。现在我把 * 删掉了:[includeIf "gitdir:~/workspace/"],相当于/home/myusername/workspace/**,现在它正常工作了,参考链接:https://dev59.com/0moy5IYBdhLWcg3wD53G#54125961 - bcag2
重要的是 /i 是扁平的,因为有驱动器字母 C:c: ... 谁知道 Git 认为什么是真相... - jeromerg
如果你使用 git config --get user.email 进行测试,请确保你实际上在一个包含 git 仓库的文件夹中,否则它将返回默认值。 - Guillermo Ruffino

0

我成功地在Windows上使用以下方法使其工作:

.gitconfig

[includeIf "gitdir:**"]
path = C:/Users/myusername/.gitconfig-personal
[includeIf "gitdir:C:/Users/myusername/Desktop/work/**"]
path = C:/Users/myusername/.gitconfig-work

.gitconfig-personal 和 .gitconfig-work

[user]
name = My Name
email = myEmail@provider.com

所以在这种情况下,它将始终默认使用我在.gitconfig-personal中设置的常规电子邮件地址,如果我进入工作文件夹中的任何存储库,则会使用.gitconfig-work中的详细信息。 (我还没有尝试使用激励选项)


“[includeIf "gitdir:**"]” 不就等于 “[include]” 吗? - go2null

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