3

Where does the "super"-repo keep track of what commit each submodule is at?

I dont see any of that info in .gitmodules

What I want to achieve is if I tag the "super"-repo, with say 1.0-alpha, then it will remember at what commit all the submodules was at that time, so when I checkout that tag later, I'll get the submodules at their correct commit position aswell.

Is this possible without manually writing down the commit-position for each submodule?

I now realize I can get that info later on by using:

git ls-tree <tag>

But then I'll have to go into each submodule and manually checkout that specific submodule at commit abc1234..

/David

1 Answer 1

4

The current commit hash for a submodule is stored in the tree object(s) associated with the commit in the master project. If you do a git ls-tree -r HEAD in your master project, each submodule is represented by a line of the form:

160000 commit <hash> <path/to/submodule>

This line indicates the commit in the submodule that should be checked out to match the commit in the master repository.

Sign up to request clarification or add additional context in comments.

4 Comments

thats kinds of what I said in the questions... but this means that if i want to go back to a tag, and have it working with the submodules it included, I have to manually go into those submodules and reset them to whatever commit they were at when the "super"-project was tagged?
No, after you do git checkout whatever in your master project, you run git submodule update, and it will look at the commit in your master project, and checkout whatever is needed in the submodule(s).
Thanks.. After switching between branches, this is what I forgot to do to get the appropriate submodule version! Do you know where that information is saved (at which commit the submodule is)?
The commit that the submodule currently has checked out is stored in the HEAD ref in the git directory associated with that submodule, which depends on your version of git. It used to be in path/to/submodule/.git, but newer versions disassociated the git-dir and the work tree for submodules, so now it lives at .git/modules/path/to/submodule in the main repository instead...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.