I understand how to use git submodule to reference a specific commit in another repo, but where is that reference actually stored? It doesn't seem to be in .gitmodules
as plain text?
The .gitmodules
file just records the path and remote URL to the submodule repository. The commit itself is stored in the tree object. You can query it like this:
git ls-tree <ref> <path>
where <ref>
is a reference to some commit (e.g. HEAD
, master
, a commit SHA sum) and <path>
is a path to a submodule.
The output looks something like this:
160000 commit <sha> <path>
where <sha>
is the commit in the submodule. The number in front has the following meaning, according to the Git book:
Notice the
160000
mode for theDbConnector
(submodule path of the example used in the book) entry. That is a special mode in Git that basically means you’re recording a commit as a directory entry rather than a subdirectory or a file.
See also this question on StackOverflow.