【问题标题】:What is the syntax for specifying Windows paths in .gitconfig?在 .gitconfig 中指定 Windows 路径的语法是什么?
【发布时间】:2015-04-15 17:34:49
【问题描述】:

我正在尝试使用include.path config described here,但我似乎无法在 Windows 上找到正确的路径语法。

我当前的 .gitconfig:

[include]
    path = 'D:\Scott\Shared\config\common.gitconfig'

但是 git 抱怨:fatal: bad config file line 2 in C:\Users\Scott/.gitconfig

为 Windows 转义路径的正确方法是什么?注意:我使用的是 Powershell 中的 git,而不是 git bash。

【问题讨论】:

    标签: windows git powershell path


    【解决方案1】:

    好的,想通了。诀窍是:

    1. 用双引号括起来
    2. 将反斜杠转换为正斜杠。
    3. 绝对路径以驱动器号 + 冒号开头

    所以上面的正确版本是:

    [include]
        path = "D:/Scott/Shared/config/common.gitconfig"
    

    【讨论】:

    • 无法在 Win 7 git 版本 1.9.5 上运行。如果我运行git config --global -l,我会得到include.path=c:/common/git/commonConfig。似乎没有读入 commonConfig 的任何内容。
    • 这对我仍然有效。请注意,我没有看到来自 git config --global -l 的配置,但它们可用于其他 git 命令(difftool、别名等)。 Windows 8.1 和git --version:1.9.5.msysgit.1
    • Scott W.:是的,我终于发现git config --global -l 似乎只是读取了配置文件而没有扩展 include.path,而其他 git 命令按预期工作。不幸的是,查看配置的简单方法不可用...
    • @Number8 指定配置文件(如--global)可防止扩展include.path,但有--includes,因此您可以在任何存储库之外使用git config --global --includes -l 或简单地使用git config -l查看全局和系统配置。
    【解决方案2】:

    根据 git bash 中pwd 的输出,我推测它可能是

    /d/Scott/Shared/config/common.gitconfig
    

    【讨论】:

    • 感谢 letitbee,尽管这似乎对我不起作用。我应该提到我使用的是 Powershell 而不是 git bash (将更新问题)。我刚刚找到了一种有效的语法,我也将其作为答案发布。
    • 如果 Windows 热衷于遵循直观的方法,叹息……这对我也不起作用。但是作者的自我回答确实如此。
    • 我假设您的推测是不正确的。 ://
    猜你喜欢
    • 1970-01-01
    • 2017-09-17
    • 1970-01-01
    • 2014-06-11
    • 1970-01-01
    • 2012-06-13
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    相关资源
    最近更新 更多