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
感謝您的回覆。我已經讚賞你的幫助,但是我已經創建了一個腳本,子模塊將遵循主要的倉庫分支。 –