我想要实现的是,每当我在我的主存储库上使用git签出时,例如:
git checkout my-branch我的子模块将跟随我的分支而不是一个独立的头。
有可能吗?如果有,怎么做?
发布于 2017-05-04 04:56:43
如果这些子模块存储库有自己的“我”分支,那么它们可以是declared to follow that branch。
cd /path/to/your/parent/repo/Foo
git config -f .gitmodules submodule.bar1.branch my-branch
git config -f .gitmodules submodule.bar2.branch my-branch
git submodule update --remote但这意味着每次您签出父回购中的分支时都要重复这一点。
torek指出in the comments,这些子模块可能有自己的子模块,因此需要--recursive选项。
您还可能希望将
--recursive和/或--no-fetch添加到git submodule update --remote命令中。 与单独的git config -f操作不同,您可能需要git submodule foreach,也可能需要使用--recursive。
git submodule foreach -q --recursive 'git config -f $toplevel/.gitmodules submodule.$name.branch my_branch'在多行以提高可读性:
git submodule foreach -q --recursive \
'git config -f $toplevel/.gitmodules submodule.$name.branch my_branch'然后,您可以将每个子模块签出到该分支:
git submodule foreach -q --recursive 'branch="$(git config -f $toplevel/.gitmodules submodule.$name.branch)"; git checkout $branch'在多行以提高可读性:
git submodule foreach -q --recursive \
'branch="$(git config -f $toplevel/.gitmodules submodule.$name.branch)"; \
git checkout $branch'https://stackoverflow.com/questions/43772039
复制相似问题