From: Stefan Zager Date: Wed, 09 May 2012 23:55:40 GMT Subject: submodule update --force Message-ID: In-Reply-To: I have a situation where I have a full source tree -- top-level repository and all submodules -- generated via `git clone -n`.  So, the directory structure and .git directories are intact, but no actual source files have been checked out. If I run `git submodule update` from the top level, some submodules get checked out, but not others.  Weird. Root cause is in the cmd_update function in git-submodule.sh, which does essentially this: sha1 = submodule revision as registered in top-level module subsha1 = HEAD revision in submodule checkout if test "$subsha1" != "$sha1" then     git checkout $sha1 fi In the submodule checkouts, HEAD is refs/heads/master.  In *some* of the submodules, the revision registered in the top-level repository is the same as HEAD.  So, for those submodules, `git submodule update` run from the top level is a no-op, because $sha1 = $subsha1.  That's true even though there are no actual source files checked out in the submodule. For other submodules, $sha1 != $subsha1, and `git submodule update` checks out the source code as expected. Confusing! According to the docs for git-submodule:        -f, --force            This option is only valid for add and update commands. When running add, allow adding an otherwise ignored            submodule path. When running update, throw away local changes in submodules when switching to a different            commit. I'd like to propose amending the documentation thusly: According to the docs:        -f, --force            This option is only valid for add and update commands. When running add, allow adding an otherwise ignored            submodule path. When running update, throw away local changes in submodules when switching to a different            commit; if not switching to a different commit, a checkout to HEAD will still be run. ... and here's the patch to implement it: diff --git a/git-submodule.sh b/git-submodule.sh index 64a70d6..8b045d9 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -536,7 +536,7 @@ Maybe you want to use 'update --init'?")"                         die "$(eval_gettext "Unable to find current revision in submodule path '\$sm_path'")"                 fi -               if test "$subsha1" != "$sha1" +               if test "$subsha1" != "$sha1" -o -n "$force"                 then                         subforce=$force                         # If we don't already have a -f flag and the submodule has never been checked out Thoughts? Thanks, Stefan