简体   繁体   中英

Tagging git submodules with release

We have a project whereby we use a lot of submodules. When branching and tagging our release I would like to ensure that the submodules state is preserved with the branch and tag. So that if we need to build the release again we can ensure the submodule is the same version as what we originally used. What is the best way to do this?

Thanks

What you are looking for is not needed because a specific version of your submodules is already linked to your commit. Because updating a submodules is something that you commit in your main repository.

Not sure to be very clear :-( but it's already done by the way submodules works...

A submodule is recorded in the parent repo as a gitlink ( a special entry in the index ).

It means the submodule state does not change when tagging or branching: the gitlink is still the same, and the submodule would checkout the same SHA1.

Making a branch in the parent repo has no effect or relation with making a branch in a submodule. Same for tags.

I know this is an old question but it has no direct answer here.

I tag just the superproject repository. Assuming your working branch is master for superproject and all submodules.

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

After you have made some changes and want to get back to v7.3 tag:

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

To get back to master use:

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

Alternatively if you have linking branches as described here there is a shortcut:

git checkout master --recurse-submodules

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM