Someone please help me understand submodules in git. I know they are getting a lot of bashing around the internet but since I assume the git developers are smart people there must a reason for the current behavior - and maybe a way to work around my problem.
So, I have a project and some submodules. The project have different branches, like:
- MyApp_version2
- MyApp_version3
- MyApp_version4
- MyApp_liteversion
- MyApp_development
My submodules doesn't update that often (maybe once a week) so I'm fine with them not being attached to the head of the submodule repository automatically.
However, when I check out an old branch - because I need to fix a bug in an old version of the software - I also need to update the submodules.
Why do I need to do this?
I would expect git to work like svn. When I commit my work in my main repo I would expect git to think something along these lines: "OK, he wants to commit his work now. I can see the submodules are currently at revision abc so when he at some point in the future get's back to this commit he probably wants the submodules at the same revision again."
I can not see a single case where you would want the submodules to stay at the current revision while you go back 3 years in your main repository. However, there must be a reason for this implementation, right?
I would really like to hear if any of you know the thoughts behind this, but in any case I would really like a solution. Is there a way to tell git: "I want to commit this work with these submodules. If I at some point go back to this state I want the submodules to be checked out at the correct version as well."
Example for clarification
My main repository is an application which needs to use SSL, and I find a SSL library (libSSL) I add as a submodule.
On Oct. 31 2010 I create a commit in my main repository (2fd4e1) while the submodule points to libSSL version 3 (c67a2d).
Time passes, libSSl gets updated to version 34, I adapt my code, life it good.
On May 14 2013 I create a new commit (28fced) and submodule points to the most recent version of libSSL (849ee1).
However, if I check out 2fd4e1 my submodule will stay at 849ee1 even though the original commit was created with c67a2d. Git knows I made the original commit with c67a2d and I don't see how you could possibly want a another submodule than the one the original commit was created with.
git checkout
to make it also do the appropriate submodule things, I wouldn't want it enabled by default... – Missiegit submodule init foo
should probably be analogous togit clone foo
if foo is not an url. And if the user want to do anything more complex than clone or checkout he can justcd foo
and call git normally. This would probably make all these obscure commands intuitive and easy to use. – Skaggsgit checout
is a local operation. In contrast,git submodule update
(which is what--recurse-submodules
implies) can involvefetch
and evenclone
. So doing this by default would fundamentally change the character ofcheckout
. I guess that is why the designers decided against it. You can change the default behavior withgit config --global submodule.recurse true
. – Monied