【发布时间】:2017-10-10 16:18:02
【问题描述】:
Git 版本: 2.13.0.windows.1
操作系统: Windows 7
CLI: Git bash
.gitconfig
[user]
name = Gyandeep Singh
email = private@email.com
[push]
default = current
[core]
autocrlf = input
[includeIf "gitdir: ~/Documents/webstorm/corporate/"]
path = .gitconfig-work
.gitconfig-work
[user]
name = Gyandeep Singh
email = corporate@email.com
- 以上两个配置文件都位于同一个目录(主目录)中。
发生了什么:在公司文件夹内的文件夹(示例测试)上打开 CLI,然后运行 git config user.email,输出为 private@email.com。
预期:结果应该是corporate@email.com。
是我做错了什么还是我的期望不正确?我确实遵循了 git 文档。
解决方案
您必须在 git 初始化目录上运行 git config --show-origin --get user.email。如果它没有被 git 初始化,那么includeIf gitdir 功能将不起作用。
这很奇怪,但却是真实的。我希望它仍然有效。
【问题讨论】:
-
确保您的项目位于目录
.../webstrom/...。也许是webstorm? -
拼写不是问题,因为我在两个地方都验证了它的相同。
-
我也无法完成这项工作,使用绝对路径
C:/...、C:\...(给出错误)、/c/...。今晚我会更深入地研究它。 -
没用过这个;但是查看文档:您是否尝试过删除
:和~之间的空格,例如[includeIf "gitdir:~/Documents/webstorm/corporate/"]? -
重要:
gitdir子句指定的路径必须结尾有斜杠,否则不起作用。所以[includeIf "gitdir/i:~/Documents/webstorm/corporate/"]有效,但[includeIf "gitdir/i:~/Documents/webstorm/corporate"]无效。 (git 2.24.1.windows.2)