I have a submodule called Helpers. When I clone my main project with --recursive, the Helpers submodule is in a detached head state (as all of the tutorials say it should be). If I now 'git status' in the main project directory, everything is clean. If I 'cd Helpers; git checkout master', I would expect nothing to change except that I am now on a named branch that I can commit to. However, without doing anything else, if I 'cd ..; git status', I see
modified: Helpers (new commits)
Why does it think there are new commits? The submodule should still be at the same point as when it was updated (in this case, cloned), no?
If the HEAD
of your submodule does not match the commit specified in the index of the parent repository then git will give you the "new commits" message. You can check which commit is specified in the index by running git ls-tree
:
$ git ls-tree master:<path_to_folder_containing_my_submodule>
160000 commit ba9d11670daf5109a52e5a2b01bca8a344897338 my_submodule
When you do a recursive git clone, git will fetch the very latest and then point HEAD
to the specified commit. If the specified commit does not match the latest commit in remote master, then master
will not equal HEAD
when you clone.
Another way to check after you do a recursive clone is to cd
into your submodule and then use git log
:
$ git log --decorate --all
commit 6a75034cc78fc637e2437bba9f5834835f56bd8f (origin/master, origin/HEAD, master)
...
commit ba9d11670daf5109a52e5a2b01bca8a344897338 (HEAD)
If HEAD
and master
point to the same commit then you can checkout master and you will not see the "new commits" message in the parent repo.