如何使用git config更新配置文件部分?

时间:2018-10-24 19:45:31

标签: git git-submodules git-config

我需要将branch = super_foo添加到test_config文件中现有的superproject部分:

$ cat .test_config
[superproject "mysuper"]
    url = https://server.com/test/mysuper

[submodule "tsn-inc"]
    url = url = https://server.com/test/foo_s
    branch = foo

这有效:

git config -f .test_config --add superproject.mysuper.branch super_foo

但是,“ mysuper”不是一个已知值,因此我在下面尝试了一下,因为将只有一个超级项目部分。

git config -f .test_config --add superproject.*.branch super_foo

它添加了一个新部分,如下所示:

[superproject "*"]
    branch = super_foo

相反,我想向现有的超级项目部分添加分支,有没有办法做到这一点?

2 个答案:

答案 0 :(得分:0)

在编写配置git config时需要确切的密钥-禁止使用模式,此处不允许使用正则表达式。因此,您必须以某种方式推断出mysuper部分。

您可以提取superproject个部分的列表:

git config --name-only --get-regex '^superproject\.' | sed  -r 's/^[^.]+\.(.*)\.[^.]+$/\1/' | sort -u

如果您知道配置中确实有一个superproject部分,或者仅对第一个部分感兴趣,则可以在如下脚本中设置值:

subsection=$(
    git config --name-only --get-regex '^superproject\.' |
    sed -rn '1,1s/^[^.]+\.(.*)\.[^.]+$/\1/p'
)
git config super --add "superproject.$subsection.branch" super_foo

答案 1 :(得分:0)

<div>
            <div class="wrapper">
                <div class="logo">
        <a href="/"><img height="35" width="35" src={Logo} alt="TriLogo"/></a>
                </div>
                <div class="text">
                    Triangular
                </div>
            </div>
            <ul>                    
                <li><a href="/">Test1</a></li>
                <li><a href="/">Test2</a></li>
                <li><a href="/">Test3</a></li>
                <li><a href="/">Sit amet</a></li>               
            </ul>
        </div>

这给了我超级项目名称。

super_name=$(git config -f .test_config --name-only --get-regexp superproject | cut -d. -f2)

做到了。