为所有Git子模块设置分支

问题描述 投票:2回答:2

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

git submodule add -b develop *

基本上我想等待递归设置.gitmodules文件中每个模块的分支。

git git-submodules
2个回答
1
投票

git submodule foreach

在每个签出的子模块中计算任意shell命令。

git submodule foreach git checkout -b develop

1
投票

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

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

commit b57e811commit c89c494commit 7a4bb55(2019年2月8日)和Denton Liu (Denton-L)(2019年2月7日)。 (由Junio C Hamano -- gitster --合并于commit 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'分支,which is the default


在Git 2.22之前,你将使用我在“How can I specify a branch/tag when adding a Git submodule?”中提到的命令

 git submodule foreach 'git config -f .gitmodules submodule.${sm_path}.branch <branch>'
© www.soinside.com 2019 - 2024. All rights reserved.