Why does git fail to fetch specific valid submodule for a given commit and how to fix it?

rbaleksandar picture rbaleksandar · Feb 23, 2017 · Viewed 31.4k times · Source

I have a git repo which has another one as a submodule dependency. In the root of my project (where the .git, .gitsubmodules etc. are) I called

git submodule update

This failed with the following message:

Fetched in submodule path 'src/framework', but it did not contain cc8c38e9d853491c672452d8dbced4666fc73ec8. Direct fetching of that commit failed.

where src/framework is a sub-directory of my project (PROJECT_ROOT/src/framework) and should be where the third-party repo lands. The given commit hash is a valid one.

I have also tried git clone --recursive <my-repo> but it fails too.

The contents of my .gitmodules is

[submodule "src/framework"]
        path = src/framework
        url = [email protected]:gh/framework.git

In addition to that I have to note the following important fact: due to recent updates in the framework repo my code breaks hence I really need to retrieve that specific version of it where things were working fine.

Answer

Alim Giray Aytar picture Alim Giray Aytar · Jun 16, 2019

Running this command after cloning (and receiving the error) solved my problem:

git submodule update --force --recursive --init --remote

Of course this is not a good solution. It is better to find and solve the underlying problem, but if anyone is in hurry, this was worked for me.