如何使用git config更新配置文件节?
我需要将如何使用git config更新配置文件节?,git,git-submodules,git-config,Git,Git Submodules,Git Config,我需要将branch=super\u foo添加到测试配置文件中现有的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_
branch=super\u foo
添加到测试配置文件中现有的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
相反,我想将分支添加到现有的superproject部分,有什么方法可以做到这一点吗?在编写configuration
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
这给了我超级项目的名称
git config -f .test_config --add superproject.$super_name.branch super_foo
这就成功了。我不知道你在做什么(因为我自己缺乏知识),但有什么理由反对在文本编辑器中编辑文件?还有,你到底想用它实现什么?我不知情地怀疑
branch
对superproject
git config -f .test_config --add superproject.$super_name.branch super_foo