Fri Oct 21 16:52:18 EDT 2011
Fixing submodule without cloning
I replaced a directory that contained a submodule by a symbolic link
and committed that change. Git noticed that, and changed the file
type to symbolic link. Now my submodule info is gone. How to fix?
From here  I find that:
The git-submodule add command does a couple of things:
It clones the submodule under the current directory and by default
checks out the master branch.
It adds the submodule's clone path to the gitmodules file and adds
this file to the index, ready to be committed.
It adds the submodule's current commit ID to the index, ready to
I already have a .gitmodules file. I don't need a clone as I do this
manually with some symlinks later. So I just need to know how to add
The commit IDs in the index can be seen using the 'ls-tree' command.
$ git ls-tree HEAD
160000 commit 4b7734dfa87e981d7e0d74b9d76e24a0425bc28f module_a
160000 commit 75e2a794db9135d98b14411f586dab9e99e26bdb module_b
So how to add them back?
Ok, first make sure the directory being added is in fact a valid git
repository (to avoid cloning). Then do something like this:
$ git submodule add <repo-uri> module_a
Adding existing repo at module_a' to the index
Now, be careful about .gitmodules : it is used by "git submodule init"
to put the repos in .git/config but it will not overwrite any entries
that are already there.