For a rails template I'd like to add a submodule of a specific tag to new rails apps. To keep this simple I'd like to avoid going into subdirectories and running git commands there.
git submodule add --branch v1.3.37 [email protected]:foo.git vendor/foo
Is what I would like to use, but it does not accept tags for the --branch
parameter:
fatal: 'origin/v1.3.37' is not a commit and a branch 'v1.3.37 cannot be created from it Unable to checkout submodule 'vendor/foo'
Is there a simple way to add a git submodule on a specific tag?
In order to add a Git submodule, use the “git submodule add” command and specify the URL of the Git remote repository to be included as a submodule. When adding a Git submodule, your submodule will be staged. As a consequence, you will need to commit your submodule by using the “git commit” command.
Use the git submodule update command to set the submodules to the commit specified by the main repository. This means that if you pull in new changes into the submodules, you need to create a new commit in your main repository in order to track the updates of the nested submodules.
Move the submodule to its new home. Edit the config file, updating the worktree path so that it points to the new location of the submodule's working directory. Edit the . gitmodules file in the root of the master repository, updating the path to the working directory of the submodule.
I don't think it is possible.
This is the submodule command line reference.
git submodule [--quiet] add [<options>] [--] <repository> [<path>]
add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--depth <depth>] [--] <repository> [<path>]
As you can see, right now it only supports branch option, and in terms of Git objects, the difference between branch and tag is discussed in here reference:
branch
A "branch" is an active line of development. The most recent commit on a branch is referred to as the tip of that branch.
tag
A ref pointing to a tag or commit object. In contrast to a head, a tag is not changed by a commit.
So, until Git team supports SHA commit checkout for submodule, you cannot checkout specific tag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With