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

发布于 2024-09-28 21:15:27 字数 410 浏览 0 评论 0 原文

可能的重复:
是否可以在 .gitconfig 中包含文件< /a>

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

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

Possible Duplicate:
Is it possible to include a file in your .gitconfig

With bash and zsh I can source subfiles in order to better organize my config.

Can I do something similar with .gitconfig?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疯狂的代价 2024-10-05 21:15:27

(2012 年 3 月)看起来这最终将很快成为可能——git 1.7.10 将在 .gitconfig 中支持此语法:

[include]
    path = /path/to/file

请参阅此处了解 git 更改及其边缘情况的详细说明。

,有几个细节值得指出:

  1. 路径扩展,例如 ~$HOME,似乎不受支持。

  2. 如果指定了相对路径,则它是相对于具有 [include] 语句的 .gitconfig 文件。即使跨链包含,这也能正常工作——例如 ~/.gitconfig 可以有:

    <前><代码>[包括]
    路径=子目录/gitconfig

    subdir/gitconfig可以有:

    <前><代码>[包括]
    路径=nested_subdir/gitconfig

    ...这将导致 subdir/nested_subdir/gitconfig 被加载。

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

(March 2012) It looks like this is finally going to be possible soon -- git 1.7.10 is going to support this syntax in .gitconfig:

[include]
    path = /path/to/file

See here for a detailed description of the git change and its edge cases.

By the way, a couple of subtleties worth pointing out:

  1. Path expansion, e.g. ~ or $HOME, does not appear to be supported.

  2. If a relative path is specified, then it is relative to the .gitconfig file that has the [include] statement. This works correctly even across chained includes -- e.g. ~/.gitconfig can have:

    [include]
        path = subdir/gitconfig
    

    and subdir/gitconfig can have:

    [include]
        path = nested_subdir/gitconfig
    

    ... which will cause subdir/nested_subdir/gitconfig to be loaded.

  3. If git can't find the target file, it silently ignores the error. This appears to be by design.

梦亿 2024-10-05 21:15:27

(2012 年 3 月):正如 Mike Morearty答案(我赞成),git 1.7.10+ 将支持此功能。


原始答案(2010年10月):

目前还没有。

正如我在中提到的,是否可以将文件包含在在您的 .gitconfig 中,您已经有 3 个单独的 gitconfig 供您组织设置:

$GIT_DIR/config

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

~/.gitconfig

用户特定的配置文件。也称为“全局”配置文件。

$(prefix)/etc/gitconfig

系统范围的配置文件

2010 年 5 月讨论了 配置文件包含问题,并发布了第一个补丁由 Ævar Arnfjörð Bjarmason 编写,但我在最新的“Git 正在做什么"。

(March 2012): As mentioned in Mike Morearty's answer (which I upvoted), git 1.7.10+ will support this feature.


Original answer (October 2010):

Currently, no.

As I mentioned in Is it possible to include a file in your .gitconfig, you already have 3 separate gitconfig for you to get your settings organized:

$GIT_DIR/config

Repository specific configuration file. (The filename is of course relative to the repository root, not the working directory.)

~/.gitconfig

User-specific configuration file. Also called "global" configuration file.

$(prefix)/etc/gitconfig

System-wide configuration file

Config File inclusion was discussed in May 2010, and a first patch was written by Ævar Arnfjörð Bjarmason, but I don't see this patch in one of the latest "what's cooking in Git".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文