2
我想达到的目标是,每当我使用git签上我的主要仓库,例如:是否有可能签出与子模块同步的主存储库的分支?
git checkout my-branch
我的子模块将遵循而不是一个分离的头我的分支。
是否有可能,如果是的话,如何?
我想达到的目标是,每当我使用git签上我的主要仓库,例如:是否有可能签出与子模块同步的主存储库的分支?
git checkout my-branch
我的子模块将遵循而不是一个分离的头我的分支。
是否有可能,如果是的话,如何?
如果这些子模块仓库有自己的我的分支,他们可以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'
您可能还想在'git子模块更新--remote'命令中添加'--recursive'和/或'--no-fetch'。不是单独的'git config -f'操作,你可能需要'git submodule foreach',也许可以用'--recursive',尽管让右边看起来很棘手。 – torek
我同意并将在稍后编辑(我正在上下班)我只是提出了一个解决方案的开始,提到了遵循子模块的分支的可能性。 – VonC
感谢您的回复。我已经赞赏你的帮助,但是我已经创建了一个脚本,子模块将遵循主要的仓库分支。 –