是否可以在 .gitconfig 中包含文件 [英] Is it possible to include a file in your .gitconfig

查看:19
本文介绍了是否可以在 .gitconfig 中包含文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的 .gitconfig 中包含一个包含我的 github 设置的文件 - 这可能吗?

I'd like to include a file in my .gitconfig that has my github settings - is this possible?

我可以这样做吗:

[core]
    include = /path/to/file

推荐答案

Git (1.7.10+) 现在 支持 .gitconfig 中的这个语法:

Git (1.7.10+) now supports this syntax in .gitconfig:

[include]
    path = /path/to/file

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

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. 环境变量扩展,例如$HOME,不支持.(~ 的扩展出现在 Git 1.7.10.2 中.)

  1. Environment-variable expansion, e.g. $HOME, is not supported. (Expansion of ~ appeared in Git 1.7.10.2.)

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

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

subdir/gitconfig 可以有:

[include]
    path = nested_subdir/gitconfig

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

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

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

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

这篇关于是否可以在 .gitconfig 中包含文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆