我可以从另一个加载一个.gitconfig文件吗?

Joh*_*hir 11 git git-config

可能重复:
是否可以在.gitconfig中包含文件

使用bash和zsh,我可以获取子文件,以便更好地组织我的配置.

我可以做类似的事.gitconfig吗?

Mik*_*rty 14

(2012年3月)看起来这很快就会成为可能 - git 1.7.10将支持这种语法.gitconfig:

[include]
    path = /path/to/file
Run Code Online (Sandbox Code Playgroud)

有关git更改及其边缘情况的详细说明,请参见此处.

顺便说一句,值得指出的一些细微之处:

  1. 路径扩展(例如~或)$HOME似乎不受支持.

  2. 如果指定了相对路径,则它相对于具有该[include]语句的.gitconfig文件.这甚至可以在链式包含中正常工作 - 例如~/.gitconfig可以:

    [include]
        path = subdir/gitconfig
    
    Run Code Online (Sandbox Code Playgroud)

    并且subdir/gitconfig可以:

    [include]
        path = nested_subdir/gitconfig
    
    Run Code Online (Sandbox Code Playgroud)

    ...将导致subdir/nested_subdir/gitconfig加载.

  3. 如果git找不到目标文件,它会默默地忽略该错误.这似乎是设计上的.


Von*_*onC 5

(2012年3月):正如Mike Morearty回答中所提到的(我赞成),git 1.7.10+将支持此功能.


原始答案(2010年10月):

目前,没有.

正如我在上面.gitconfig提到的那样,你可以在你的文件中包含一个文件,你已经有了3个单独的gitconfig来为你设置组织:

$GIT_DIR/config
Run Code Online (Sandbox Code Playgroud)

存储库特定的配置文件.(文件名当然是相对于存储库根目录而不是工作目录.)

~/.gitconfig
Run Code Online (Sandbox Code Playgroud)

用户特定的配置文件.也称为"全局"配置文件.

$(prefix)/etc/gitconfig
Run Code Online (Sandbox Code Playgroud)

系统范围的配置文件

2010年5月讨论了配置文件包含,第一个补丁由ÆvarArnfjörðBjarmason编写,但我没有在最新的" Git中的烹饪 "中看到这个补丁.