是否可以将 git 子模块连接到主项目分支上的特定提交?

Is it possible to connect a git submodule to a specific commit on a branch on the main project?

我和 git version 2.8.0.windows.1 有这种情况。

我有一个主项目的“release”分支,每次有新版本我都会推送到那里。

这个项目有一个并行开发的子模块,所以我希望那里有很多提交。

Project Master 分支和 Submodule Master 分支(几乎)并行进行。

大师提交 1 => 大师提交 2 => 大师提交 3 => 大师提交 4
子模块提交 1 => 子模块提交 2 => 子模块提交 3 => 子模块提交 4

在这种情况下,主提交 4子模块提交 4.

对齐

当有人试图获得 release 分支时,问题出现了。
因此,如果我在 Master Commit 1 推送 release 分支,而当我们在 Master Commit 4[=] 时有人拉发布分支57=] 我们有一个错位(因为 releaseMaster Commit 1 有关,而现在我们在 Submodule Commit 4 ).

我看到的解决方案是以某种方式强制 Submodule Commit 1release 分支,但我还不知道怎么做。

我知道一个很好的解决方案就是按照 here 的解释在子模块上添加一个分支或标签。

但是我对子模块存储库没有权限,所以我在那里设置分支或标签并不容易。

是否有任何解决方法可以在我的发布分支上强制执行 特定子模块提交 并且 而不仅仅是子模块 branch/tag

这就是子模块的工作方式,所以我不明白你的问题。让我尝试增强或修复您的工作流程。您需要 release 分支中的每个提交都指向子模块中的相应提交,对吗?这很简单:在 release 分支更新子模块之前,检查子模块中的正确提交并在超级项目中提交更改:

# In the superproject
git checkout release

cd subdir # into the submodule
git checkout master # reconcile detached HEAD
git pull origin master # update the submodule
git checkout some-sha1 # if you don't want the latest commit in master

cd .. # back into superproject
git add subdir
git commit -m "Update submodule"

现在 git clone --recursive 超级项目获得子模块的每个人都指向分支中每个提交的正确提交 release