git tag operation on submodule multi-module (and synchronization to remote branch)

Posted by zingbats on Tue, 04 Jun 2019 23:15:03 +0200

Preface

git's operation on multiple modules requires the following commands

git submodule foreach 

Simply add the required operations to the back, and they will be executed module by module. For example:

git submodule foreach git stash

It traverses all the sub-modules and stores them.

Fight tag

Because git submodule foreach only operates on sub-modules but not on the main warehouse, it is necessary to tag the main warehouse separately if the same tag is applied to all warehouses.

git tag tag_test

Then tag the sub-module and enter the command
git submodule foreach git tag tag_test
It will be tag_test module by module, enter the following command to view:
git submodule foreach git tag
Result:

Entering 'XXXXXXXXModule'
tag_test
Entering 'XXXXXXXXModule'
tag_test
Entering 'XXXXXXXXUtilsLibrary'
tag_test
Entering 'XXXXXXXX_Master'
tag_test
Entering 'XXXXXXXXModule'
tag_test
Entering 'XXXXXXXXModule'
tag_test
Entering 'XXXXXXXXLibrary'
tag_test
Entering 'XXXXXXXXApiModule'
tag_test
Entering 'XXXXXXXXModule'
tag_test

They have been tag ged successfully.

Push to gitlab

The main warehouse and the module warehouse still need to be pushed separately
Push the tag that the sub-module just typed up:
git submodule foreach git push origin tag_test
Result

Entering 'XXXXXXXXModule'
Total 0 (delta 0), reused 0 (delta 0)
To http://gitlab.XXXXXXXXModule.git
 * [new tag]         tag_test -> tag_test
Entering 'XXXXXXXXModule'
Total 0 (delta 0), reused 0 (delta 0)
To http://gitlab.XXXXXXXXModule.git
 * [new tag]         tag_test -> tag_test
Entering 'XXXXXXXXUtilsLibrary'
Total 0 (delta 0), reused 0 (delta 0)
To http://gitlab.XXXXXXXXUtilsLibrary.git
 * [new tag]         tag_test -> tag_test
Entering 'XXXXXXXX_Master'
Total 0 (delta 0), reused 0 (delta 0)
To http://gitlab.XXXXXXXX_Master.git
 * [new tag]         tag_test -> tag_test
Entering 'XXXXXXXXModule'
Total 0 (delta 0), reused 0 (delta 0)
To http://gitlab.XXXXXXXXModule.git
 * [new tag]         tag_test -> tag_test
Entering 'XXXXXXXXModule'
Total 0 (delta 0), reused 0 (delta 0)
To http://gitlab.XXXXXXXXModule.git
 * [new tag]         tag_test -> tag_test
Entering 'XXXXXXXXLibrary'
Total 0 (delta 0), reused 0 (delta 0)
To http://gitlab.XXXXXXXXLibrary.git
 * [new tag]         tag_test -> tag_test
Entering 'XXXXXXXXApiModule'
Total 0 (delta 0), reused 0 (delta 0)
To http://gitlab.XXXXXXXXApiModule.git
 * [new tag]         tag_test -> tag_test
Entering 'XXXXXXXXModule'
Total 0 (delta 0), reused 0 (delta 0)
To http://gitlab.XXXXXXXXModule.git
 * [new tag]         tag_test -> tag_test

Then push the main warehouse:
git push origin tag_test
Push successfully

Total 0 (delta 0), reused 0 (delta 0)
To http://gitlab.XXXXXXXX_Master.git
 * [new tag]         tag_test -> tag_test

Delete tag

Because the tag has been pushed to the remote, it is a bit more difficult to delete the remote tag. First, delete the tag from the local area:
git tag -d tag_test
Then, remotely delete. The delete command is also push, but in the following format:
git push origin :refs/tags/tag_test

Delete successfully:

To http://gitlab.XXXXXXXX_Master.git
 - [deleted]         tag_test

Then the tag is deleted module by module locally:
git submodule foreach git tag -d tag_test
Then remotely delete:
git submodule foreach git push origin :refs/tags/tag_test
Delete successfully:

Entering 'XXXXXXXXModule'
To http://gitlab.XXXXXXXXModule.git
 - [deleted]         tag_test
Entering 'XXXXXXXXModule'
To http://gitlab.XXXXXXXXModule.git
 - [deleted]         tag_test
Entering 'XXXXXXXXUtilsLibrary'
To http://gitlab.XXXXXXXXUtilsLibrary.git
 - [deleted]         tag_test
Entering 'XXXXXXXX_Master'
To http://gitlab.XXXXXXXX_Master.git
 - [deleted]         tag_test
Entering 'XXXXXXXXModule'
To http://gitlab.XXXXXXXXModule.git
 - [deleted]         tag_test
Entering 'XXXXXXXXModule'
To http://gitlab.XXXXXXXXModule.git
 - [deleted]         tag_test
Entering 'DiscoveryLibrary'
To http://gitlab.intsig.net/CCAndr/DiscoveryLibrary.git
 - [deleted]         tag_test
Entering 'XXXXXXXXApiModule'
To http://gitlab.XXXXXXXXApiModule.git
 - [deleted]         tag_test
Entering 'XXXXXXXXModule'
To http://gitlab.XXXXXXXXModule.git
 - [deleted]         tag_test

Rename tag

git does not rename tag commands directly, so other methods are needed.
Refer to this website

#Create an old tag
git tag old
#Create a new label that relies on old
git tag new
#Delete old labels
git tag -d old
git push origin :refs/tags/old
#Upload new labels
git push origin --tags

The operation of the module is similar, but you need to add a sentence before each command.
git submodule foreach

Topics: git GitLab