why .gitconfig [includIf]覆盖默认配置

sqxo8psd  于 2023-06-04  发布在  Git
关注(0)|答案(1)|浏览(185)

我有两个键到不同的github帐户,并有配置~/.gitconfig

[user]
        name = example
        email = example@example.com
[pull]
        rebase = true
[rebase]
        autoStash = true
[filter "lfs"]
        clean = git-lfs clean -- %f
        smudge = git-lfs smudge -- %f
        process = git-lfs filter-process
        required = true
[includeIf "gitdir/i:/Users/example/Documents/github_2/"]
    [core]
        sshCommand = "ssh -i ~/.ssh/github2_key"

然后,我去一个不在/Users/example/Documents/github_2/的文件夹,运行git clone github1_private_project,git告诉我Please make sure you have the correct access rights
它可以从/Users/example/Documents/github_2/中的帐户'github2'中git克隆项目
git版本:

% git -v
git version 2.39.2 (Apple Git-143)
fv2wmkja

fv2wmkja1#

includeIf的语法应该是(参见文档):

[includeIf "gitdir/i:/Users/example/Documents/github_2/"]
path = </path/to/includeFile>

语法

[includeIf "gitdir/i:/Users/example/Documents/github_2/"]
    [core]
        sshCommand = "ssh -i ~/.ssh/github2_key"

实际上意味着

[includeIf "gitdir/i:/Users/example/Documents/github_2/"]
# No `path` hence no include

[core]
    sshCommand = "ssh -i ~/.ssh/github2_key"

其中密钥core.sshCommand总是(无条件地)被定义。

相关问题