git submodules

Linus Torvalds torvalds at linux-foundation.org
Fri Nov 10 13:59:10 PST 2017


On Fri, Nov 10, 2017 at 1:39 PM, Dirk Hohndel <dirk at hohndel.org> wrote:
>
> Now comes the 64 Dollar question. Can I trick you into you setting this
> up the right way, or do I have to do it wrong first, have you yell at me,
> and then have you fix it?

You should do it, and I think you should do it in a private repository
to play around with it first.

But I'll give you the command to get started:

    git submodule add -b Subsurface-branch
git://github.com/Subsurface-divelog/libdc.git libdivecomputer

which is actually pretty self-explanatory. It says "add a new
submodule, using the branch 'Subsurface-branch' from the repository at
that github address, and put it in the subdirectory
'libdivecomputer'".

NOTE! That does _not_ commit anything, but it adds the data to the git
index. So you can add several subprojects, and add whatever scripting
updates, and then commit them all together,

But at this point, just do

   git status

and perhaps

   git diff HEAD

(note that "git diff" will be empty, because the submodule has already
been added to the index, the same way 'git add pathname" adds your
changes to 'pathname' to the index file to prepare them for
committing).

If you do that "git diff HEAD", you'll also see what git really is
doing under the hood. It added a ".gitmodules" file that contains some
metadata about the submodules you have, and it added a special
"gitlink" to the index for "libdivecomputer". In your checked out
tree, "libdivecomputer/" is a directory, but in the git index file, it
isn't a directory, but a link to a particular commit in the
subproject.

Anyway, play around with it. I would suggest you first try things out
in a throw-away clone of your regular subsurface repository. That way
you can play around all you like, make all the mistakes you can, and
then if you get confused you can just blow it all away and start from
scratch.

               Linus


More information about the subsurface mailing list