In order to get a project with submodules, you run this command after cloning the project:
git submodule init
This command reads .gitmodules
and writes information about the module into the index.
Then you run
git submodule update
Which gets a certain commit of the submodule repository.
How does git know which commit in particular to get? Where is this information stored?
The reason I do not understand this, is because I can see that it's not in .gitmodules
but I think it's also unlikely to be in the index, since it's git submodule init
that writes it into the index. So it leaves this information no logical place to be, that I can think of.
When the above is answered, how do we change this commit number, so that a submodule can be retrieved at a different commit next time?
Note: I read this, this and this. I may have missed it but I did not find the answer to my question.
Update 1
I'd like a clarification on larsks's answer below. It is excellent answer, however I'd like to clarify the following.
In the answer, git checkout a18306f
command is used. I'd like to see if I there is a shortcut to doing this for the latest commit on the branch. In order to run this command currently I need to do this:
git branch
## Note the current branch name, let's assume it's master,
## use this branch name in the following command
git log -1 origin/master
## Now note the commit number.
## This is where a18306f in the example above comes from in my use case.
## And finally
git checkout a18306f
Is there a better way of doing that?