Reputation: 2155
I have a project, SubProj, which I want to include as a submodule in MainProj. However, I want to make sure that any releases I do of MainProj also include a particular version of SubProj to ensure all dependencies are satisfied.
In other words, when I tag a particular commit of MainProj as a new version V1.0, I also want to include e.g. SubProj V1.3, so that whenever someone checks out MainProj 1.0 the submodule will always initialise to V1.3, rather than whatever commit in SubProj HEAD is pointing to at the time.
Is this possible?
Upvotes: 1
Views: 197
Reputation: 5163
All you need is to update your MainProj#V1.0 to use the SHA of SubProj#V1.3
The philosophy of Git submodules is storing the specific commit SHA value of a submodule against any state of the main repository. Having said that following commands should do the needful:
Let's go to a branch say V1.0 of the MainProj:
$ cd main-repo-directory
$ git checkout V1.0
Let's find the SubProj commit id corresponding to V1.3
$ cd <sub-module-directory>
$ git log # Pick the commit SHA id corresponding to V1.3, say <sub-prev-commit-sha>
$ git reset --hard <sub-prev-commit-sha>
Now, just update the MainProj#V1.0 to refer to the SubProj#V1.3
$ cd main-repo-directory
$ git add <sub-module-directory>
$ git commit -m 'Tagging SubProj#V1.3 to MainProj#V1.0'
$ git push
Now, if somebody checks out MainProj#V1.0 then on init/update of the submodule it will get to SubProj#V1.3, not the latest state of the submodule or SubProj.
Upvotes: 1
Reputation: 1858
Sure this can be done, but this cannot be done with a one command - done kind of solution. You will have to
post-checkout
hook that your users have to download and add to their .git/hooks
directory in their repository that takes care of all of this.Unfortunately, I cannot think of any easier solution right now.
Upvotes: 0