设置所有Git子模块的分支 [英] Set branch for all Git Submodules

查看:713
本文介绍了设置所有Git子模块的分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个命令为所有现有的 Git子模块设置相同的分支名称

Is there a command to set the same branch name for all existing Git Submodules

git submodule add -b develop *

基本上,我需要一种方法来递归地为.gitmodules文件中的每个模块设置分支.

Basically I need a way to recursively set the branch for each module in the .gitmodules file.

推荐答案

寻找一种在.gitmodules文件中递归设置分支的方法

Looking for a way to recursive set the branch in the .gitmodules file

在Git 2.22(四年后的2019年第二季度)中,您将能够使用git submodule set-branch -b <abranch>,因为"git submodule"会学习"set-branch"子命令,该子命令允许 submodule.*.branch要修改的设置.

With Git 2.22 (Q2 2019, four years later), you will be able to use git submodule set-branch -b <abranch>, because "git submodule" learns "set-branch" subcommand that allows the submodule.*.branch settings to be modified.

请参见提交b57e811 提交7a4bb55 (2019年2月7日),由 Denton Liu(Denton-L).
(由 Junio C Hamano-gitster-合并在

See commit b57e811, commit c89c494 (08 Feb 2019), and commit 7a4bb55 (07 Feb 2019) by Denton Liu (Denton-L).
(Merged by Junio C Hamano -- gitster -- in commit 01f8d78, 25 Apr 2019)

submodule:教导set-branch子命令

这教导了git-submodule set-branch子命令,该子命令允许 子模块的分支可以通过瓷器命令设置,而无需 必须手动操作.gitmodules文件.

submodule: teach set-branch subcommand

This teaches git-submodule the set-branch subcommand which allows the branch of a submodule to be set through a porcelain command without having to manually manipulate the .gitmodules file.

对于您的情况,对于所有子模块,请使用

In your case, for all submodules, using git submodule foreach:

git submodule foreach 'git submodule set-branch --branch aBranch -- ${sm_path}'
git submodule foreach 'git submodule set-branch --default -- ${sm_path}'

(最后一行设置了master分支,这是默认)

(the last line set the 'master' branch, which is the default)

在Git 2.22之前,您将使用在添加Git子模块时如何指定分支/标记的命令. "

Before Git 2.22, you would use the command I mentioned in "How can I specify a branch/tag when adding a Git submodule?"

 git submodule foreach 'git config -f .gitmodules submodule.${sm_path}.branch <branch>'


注意:Git 2.24(2019年第四季度)明确说明--default--branch选项是互斥的.


Note: Git 2.24 (Q4 2019) makes clear the --default and --branch options are mutually exclusive.

请参见提交40e747e (2019年9月16日): //github.com/Denton-L"rel =" noreferrer>刘登顿(Denton-L).
(由 Junio C Hamano-gitster-合并在

See commit 40e747e (16 Sep 2019) by Denton Liu (Denton-L).
(Merged by Junio C Hamano -- gitster -- in commit 7f17913, 07 Oct 2019)

这篇关于设置所有Git子模块的分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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