Reputation: 113
I have three repositories: A, B, C (c++ code)
A and B are independent projects and both depends on C. The association has been made with git submodule
I create now a new project D that depends on A and B, so now C is referred two times
The project structure would be similar to the following:
D
|--A
| |
| C
|
|--B
|
C
Since different versions of D correspond to different versions of A and B I'd like to have a way to keep them synced while checking out between versions.
I was thinking about removing the submodule associations and switch to repo for all A, B and D. Does it make sense? Is there a better way to do it using only git?
Thank you
Upvotes: 2
Views: 2177
Reputation: 38106
If your project D
is contribute to repo A
and B
, you can add them as submodules for your project D
.
But there is no way to checkout the submodules to a certain versions at the same time when you checkout a certain version for project D
. The work around is use related version of D
for A
and B
tags, and execute a script to checkout A
and B
to related versions.
Such as v3.0
for D
is the version related to v1.0
of A
and v2.0
of B
, so you can add the tags with the version v3.0.1.0
in A
and v3.0.2.0
in B
. When you checkout v3.0
for D
, then you can run a script to checkout A
and B
to the version start with v3.0*
.
If your project D
is not contribute to repo A
and B
, you can remove the submodule associations. The code from A
and B
just as the subfolders for your project D
and the versions of folder A
and folder B
can sync with the version for your project D
all the time.
Upvotes: 1
Reputation: 6066
One alternative to submodules that I'm using extensively within the CMake projects, is to have all the modules as independent "libraries" and use them via the find_package() CMake command (see e.g. https://cmake.org/Wiki/CMake:How_To_Find_Libraries or https://stackoverflow.com/a/20857070/1274747). Each dependency provides its own find script which is installed together with the library, and the dependent project can use it to localize the library.
That ways the project is not directly dependent on the particular "dependency" commit (but can still depend on a particular library version, as the version dependency can be also handled via the find scripts, see e.g. the FindBoost.cmake, which also handles the required version of Boost library if specified).
Upvotes: 1