是否有命令为所有现有的 Git 子模块设置相同的分支名称
git submodule add -b develop *
基本上我需要一种方法来递归地设置.gitmodules
文件中每个模块的分支。
使用寻找一种递归设置.gitmodules文件中分支的方法
Git 2.22(四年后的 2019 年第 2 季度),您将能够使用 git submodule set-branch -b <abranch>
,因为git submodule
学习set-branch
子命令,该命令允许 submodule.*.branch
要修改的设置。
请参阅提交 b57e811、提交 c89c494(2019 年 2 月 8 日)和提交 7a4bb55(2019 年 2 月 7 日),作者:Denton Liu ( Denton-L
).
(由Junio C Hamano -- gitster
-- 在提交01f8d78中合并,2019年4月25日)
submodule
:示教set-branch
子命令
这
git-submodule
set-branch
子命令,该子命令允许通过瓷命令设置子模块的分支,而无需手动操作.gitmodules
文件。
在您的情况下,对于所有子模块,使用 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
分支,这是默认值)
在 Git 2.22 之前,您将使用我在"添加 Git 子模块时如何指定分支/标签?
git submodule foreach 'git config -f .gitmodules submodule.${sm_path}.branch <branch>'
<小时 />注意:Git 2.24(2019 年第 4 季度)明确指出--default
和--branch
选项是互斥的。
参见提交 40e747e (2019 年 9 月 16 日),作者 Denton Liu ( Denton-L
).
(由Junio C Hamano -- gitster
-- 在提交 7f17913 中合并, 07 Oct 2019)
请参阅git submodule foreach
。
计算每个检出子模块中的任意 shell 命令。
git submodule foreach git checkout -b develop