title: Where is a submodule commit number stored (and how do I change it)?
body: <p>In order to get a project with submodules, you run this command after cloning the project:</p>
  
  <pre><code>git submodule init
  </code></pre>
  
  <p>This command reads <code>.gitmodules</code> and writes information about the module into the index.</p>
  
  <p>Then you run </p>
  
  <pre><code>git submodule update
  </code></pre>
  
  <p>Which gets a certain commit of the submodule repository.</p>
  
  <p>How does git know which commit in particular to get? Where is this information stored? </p>
  
  <p>The reason I do not understand this, is because I can see that it's not in <code>.gitmodules</code> but I think it's also unlikely to be in the index, since it's <code>git submodule init</code> that writes it into the index. So it leaves this information no logical place to be, that I can think of.</p>
  
  <p>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?</p>
  
  <p>Note: I read <a href="https://git-scm.com/book/en/v2/Git-Tools-Submodules" rel="noreferrer">this</a>, <a href="https://git-scm.com/docs/git-submodule" rel="noreferrer">this</a> and <a href="http://www.speirs.org/blog/2009/5/11/understanding-git-submodules.html" rel="noreferrer">this</a>. I may have missed it but I did not find the answer to my question.</p>
  
  <p><strong>Update 1</strong></p>
  
  <p>I'd like a clarification on larsks's answer below. It is excellent answer, however I'd like to clarify the following.</p>
  
  <p>In the answer, <code>git checkout a18306f</code> 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:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Is there a better way of doing that?</p>