Git submodule - 如何在从主 repo 拉取时保持子模块更新
Git submodule - How to keep the submodule updated when pulling from the main repo
我们有主 git 存储库和一个 git 子模块。对于这个问题,主存储库确实只有一个主分支,而子模块确实有两个分支 - X 和 Y.
假设 Coder A 刚刚切换到子模块分支 X 并应用了一些小的更改。
编码器 B 它在子模块分支 Y 上。
现在 A 推送到远程并且 B 拉取 - 然后它看起来不像 B 的活动子模块提交(在其本地计算机上)自动更改为 A 推送到分支 X 的提交,即使 A 主动提交更改的子模块提交。
而对于 B,它们在分支 Y 上的版本保持活动状态。
如果 B 现在手动从存储库中拉取并将分支设置为 X,一切都会恢复正常。
我们如何实现子模块更改/活动提交在从主存储库拉取时自动同步?
我们使用源代码树作为 Git GUI,如果这样可以使任何解释更容易。
then it does not seam like B's active submodule commit (on their local machine) gets automatically changed to the commit that A pushed on branch X, even though A actively committed the changed submodule commit
You need to be sure A committed and push from the submodule, and then add/commit and push from the parent repo (为了记录新的子模块SHA1 )
Since Git 1.7.5、git pull
也应该更新子模块。
用 git submodule update --init --recursive
仔细检查
但是不要忘记“更新子模块”只会检查它的 SHA1,而不是分支。除非一个submodule is set to track a branch,而你做一个git submodule update --recursive --remote
.
即使那样,它也会拉 一个 分支(X 或 Y),而不是两者。
A friend just told us that the repo on my friends machine might be broken. So we re-cloned it from Origin and now everything just works.
I'm now looking into tracking branches with submodules, to avoid the "checked out HEAD" issue. Can you recommend that?
如“True Nature of Submodules”中所述,子模块一开始总是处于分离的 HEAD 模式。
您仍然可以强制它跟随分支并自我更新:请参阅“git submodule tracking latest”。
这意味着以下命令将在拉出子模块必须遵循的分支后更新子模块内容:
git submodule update --remote
我们有主 git 存储库和一个 git 子模块。对于这个问题,主存储库确实只有一个主分支,而子模块确实有两个分支 - X 和 Y.
假设 Coder A 刚刚切换到子模块分支 X 并应用了一些小的更改。
编码器 B 它在子模块分支 Y 上。
现在 A 推送到远程并且 B 拉取 - 然后它看起来不像 B 的活动子模块提交(在其本地计算机上)自动更改为 A 推送到分支 X 的提交,即使 A 主动提交更改的子模块提交。
而对于 B,它们在分支 Y 上的版本保持活动状态。
如果 B 现在手动从存储库中拉取并将分支设置为 X,一切都会恢复正常。
我们如何实现子模块更改/活动提交在从主存储库拉取时自动同步?
我们使用源代码树作为 Git GUI,如果这样可以使任何解释更容易。
then it does not seam like B's active submodule commit (on their local machine) gets automatically changed to the commit that A pushed on branch X, even though A actively committed the changed submodule commit
You need to be sure A committed and push from the submodule, and then add/commit and push from the parent repo (为了记录新的子模块SHA1 )
Since Git 1.7.5、git pull
也应该更新子模块。
用 git submodule update --init --recursive
但是不要忘记“更新子模块”只会检查它的 SHA1,而不是分支。除非一个submodule is set to track a branch,而你做一个git submodule update --recursive --remote
.
即使那样,它也会拉 一个 分支(X 或 Y),而不是两者。
A friend just told us that the repo on my friends machine might be broken. So we re-cloned it from Origin and now everything just works.
I'm now looking into tracking branches with submodules, to avoid the "checked out HEAD" issue. Can you recommend that?
如“True Nature of Submodules”中所述,子模块一开始总是处于分离的 HEAD 模式。
您仍然可以强制它跟随分支并自我更新:请参阅“git submodule tracking latest”。
这意味着以下命令将在拉出子模块必须遵循的分支后更新子模块内容:
git submodule update --remote