使用标签(Tagging)对git子模块进行版本发布

3
我们有一个项目,其中使用了许多子模块。在分支和标记发布时,我希望确保子模块的状态与分支和标记一起被保留。这样,如果我们需要重新构建发布,我们就可以确保子模块的版本与最初使用的版本相同。如何做到最好? 谢谢。

我在这里没有看到问题。在你的发布分支中,Git本质上将子模块视为提交。只要分支仍然指向相同的子模块提交,事情就应该是稳定的。我有什么遗漏吗? - Tim Biegeleisen
3个回答

1
你需要的内容不必要,因为特定版本的子模块已经链接到你的提交中。 因为更新子模块是在主存储库中提交的操作。可能不是非常清楚,但这已经通过子模块的工作方式完成了...

1

子模块被记录在父存储库中作为一个gitlink索引中的特殊条目)。

这意味着当打标签或分支时,子模块状态不会改变:gitlink仍然是相同的,子模块会检出相同的SHA1。

在父存储库中创建分支对于在子模块中创建分支没有影响或关系。标签也是一样。


0

我知道这是一个老问题,但这里没有直接的答案。

我只标记了超级项目存储库。假设您的工作分支是超级项目和所有子模块的master

C:\SuperProject>git --version
git version 2.23.0.windows.1

C:\SuperProject>git status
On branch master
Your branch is up to date with 'origin/master'.

C:\SuperProject>git tag v7.3

在您进行了一些更改并想要返回到v7.3标签时:

C:\SuperProject>git checkout v7.3
Note: switching to 'v7.3'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 3965477 =
M       submodule

C:\SuperProject>git submodule update --init --recursive
Submodule path 'submodule': checked out 'd9aedca7de2b9fcd873a7823c492ae32bd4b28b7'

C:\SuperProject>cd submodule

C:\SuperProject\submodule>git status
HEAD detached at d9aedca
nothing to commit, working tree clean

要返回主分支,请使用以下命令:

cd C:\SuperProject
git checkout master
git submodule foreach --recursive git checkout master

如果您有像这里描述的链接分支,那么有一个快捷方式:

git checkout master --recurse-submodules

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接