Ad

`git Submodule Update` Doesn't Checkout The Commit In The Submodule

- 1 answer

I've got following problem: When I'm checkout out a specific commit of the superproject and run git update submodules, the commit of the submodule is not checked out, although that is what this command should do according to the manpage, internet blog posts and so on. I still manually have to run git submodule <path/to/submodule> to check the correct commit out.

Does anyone know what I could be that makes git behave that way? I'm using git version 2.11.0.


Working tree is clean.

[email protected]:~/projects/testcompile/superproject$ git status
HEAD detached at origin/master
nothing to commit, working tree clean

The right commit for submodule problematic_submodule is checked out. (Its line is not prefixed with +/-.)

[email protected]:~/projects/testcompile/superproject$ git submodule
+321fce0da25208bf886d85ce4a2f1cefc02bbfff modules/libgksl (v1.2-9-g321fce0)
 ... some other modules ...
 9acb4a5d28d1ac785fce17799d58e21cc437b77d modules/problematic_submodule (v0.19-3355-g9acb4a5d2)

I'm checkout out the local master of the superproject, which is not yet pushed:

[email protected]:~/projects/testcompile/superproject$ git checkout master
Previous HEAD position was 4b58c94... Merge branch 'dev' into 'master'
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Now I want to update the submodules so they have the correct commits checked out:

[email protected]:~/projects/testcompile/superproject$ git submodule update --recursive
Fetched in submodule path 'modules/libgksl', but it did not contain a20f22f989afbcbb620303a6b418de8093c71259. Direct fetching of that commit failed.

Alas, problematic_submodule is still on the wrong commit. (Note that the line is prefixed with an +.)

[email protected]:~/projects/testcompile/superproject$ git submodule
+321fce0da25208bf886d85ce4a2f1cefc02bbfff modules/libgksl (v1.2-9-g321fce0)
 ... some other modules ...
+9acb4a5d28d1ac785fce17799d58e21cc437b77d modules/problematic_submodule (v0.19-3355-g9acb4a5d2)

I have to specify problematic_submodule so it gets checked out:

[email protected]:~/projects/testcompile/superproject$ git submodule update modules/problematic_submodule/
Submodule path 'modules/problematic_submodule': checked out '24b46f28edf9c75bf8a7bcf4cac7aa65564c88c9'

Only now the correct commit of problematic_submodule is checked out. (The line is no longer prefixed with an +.)

[email protected]:~/projects/testcompile/superproject$ git submodule
+321fce0da25208bf886d85ce4a2f1cefc02bbfff modules/libgksl (v1.2-9-g321fce0)
 ... some other modules
 24b46f28edf9c75bf8a7bcf4cac7aa65564c88c9 modules/problematic_submodule (v0.19-3551-g24b46f28e)
Ad

Answer

It seems the reason for git submodule update failing to checkout the correct commit in submodule problematic_submodule was that it aborted when not being able to checkout the desired commit for submodule libgksl.

[email protected]:~/projects/testcompile/superproject$ git submodule update --recursive
Fetched in submodule path 'modules/libgksl', but it did not contain a20f22f989afbcbb620303a6b418de8093c71259. Direct fetching of that commit failed.

Apparantly, this stopped the whole submodule update action.

I was able to resolve my problem by conducting following steps:

1. Changing into modules/libgksl and checking-out an existing commit.

2. Going back into the superproject, git add modules/libgksl, and committing.

Now the superproject is in a healthy state again. When I change the checked-out commit of a submodule and store its SHA1 in the superproject by adding and committing, git submodule update is from now on able to update the submodule accordingly.

Ad
source: stackoverflow.com
Ad