我们有一个项目,其中使用了许多子模块。在分支和标记发布时,我希望确保子模块的状态与分支和标记一起被保留。这样,如果我们需要重新构建发布,我们就可以确保子模块的版本与最初使用的版本相同。如何做到最好? 谢谢。
我知道这是一个老问题,但这里没有直接的答案。
我只标记了超级项目存储库。假设您的工作分支是超级项目和所有子模块的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