我希望使用"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。
git
2.20。只能在~/GitRepos/Other/
下的工作树中工作,而不能在~/GitRepos/Other/
的根目录下工作。仔细检查git版本、路径和语法。包含的设置应该放在它们要覆盖的设置之后,很可能是在~/.gitconfig
的最后。 - undefinedincludeif
条件的末尾多了一个不必要的星号,但这似乎不是你的情况。 - undefinedincludeIf
来替换user.email
- 完美运行。"同时执行ssh -T github.com-work会显示个人用户名" 这是一个完全不同的问题,与ssh
配置有关,与includeIf
无关。 - undefinedgit config --list --show-origin
命令,查看 user.name 和 user.email 的配置信息。 - undefined