Git“includeIf”指令在Ubuntu上无法正常工作

3

我希望使用"includeIf"指令为"work"目录内的项目指定单独的gitconfig设置。

我有一个~/.gitconfig文件:

[user]
        name = Dustin Michels
        email = my@personal-email.com

(...)

[includeIf "gitdir:~/GitRepos/Work/"]
        path = ~/.gitconfig-work

And ~/.gitconfig-work:

[user]
        name = Dustin Michels
        email = my@work-email.com

当我进入~/GitRepos/Work/目录或其中的一个Git项目时,仍然看到旧的设置。
$ git config user.email

me@personal-email.com

或者

$ git config --list

user.name=Dustin Michels
user.email=me@personal-email.com
(...)
includeif.gitdir:~/GitRepos/Other/.path=/.gitconfig-work

看起来指令没有被识别?或者有其他问题?我正在使用Ubuntu和git版本2.25.1。


对我来说没问题。Debian 10,git 2.20。只能在~/GitRepos/Other/下的工作树中工作,而不能在~/GitRepos/Other/的根目录下工作。仔细检查git版本、路径和语法。包含的设置应该放在它们要覆盖的设置之后,很可能是在~/.gitconfig的最后。 - undefined
我在includeif条件的末尾多了一个不必要的星号,但这似乎不是你的情况。 - undefined
@phd 在工作树内是有效的,但是在 git config --list 中存在重复的用户名,那么会使用哪一个呢?另外,执行 ssh -T github.com-work 会打印个人用户名。 - undefined
@kailashyogeshwar "git config --list中存在重复的用户名" 对我来说不是问题。我使用includeIf来替换user.email - 完美运行。"同时执行ssh -T github.com-work会显示个人用户名" 这是一个完全不同的问题,与ssh配置有关,与includeIf无关。 - undefined
尝试运行 git config --list --show-origin 命令,查看 user.name 和 user.email 的配置信息。 - undefined
你解决了吗?我也看到一样的。 - undefined
2个回答

1

如果你从网站复制内容,请确保检查并重新输入引号。


0
根据git-config文档,可能是路径中有大小写字母拼写错误。此外,~字符指向您的HOME变量的值,如果它不是/home可能会导致问题。
如果是这样,请替换为:
[includeIf "gitdir/i:/home/GitRepos/Work/"]

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