Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 553
rbaleksandar Avatar asked Feb 23 '17 13:02

rbaleksandar


People also ask

How do you fix a dirty submodule?

You can fix it by: either committing or undoing the changes/evolutions within each of your submodules, before going back to the parent repo (where the diff shouldn't report "dirty" files anymore). To undo all changes to your submodule just cd into the root directory of your submodule and do git checkout .

How do I initialize a git submodule?

If you already cloned the project and forgot --recurse-submodules , you can combine the git submodule init and git submodule update steps by running git submodule update --init . To also initialize, fetch and checkout any nested submodules, you can use the foolproof git submodule update --init --recursive .

Will git pull update submodules?

Once you have set up the submodules you can update the repository with fetch/pull like you would normally do. To pull everything including the submodules, use the --recurse-submodules and the --remote parameter in the git pull command .

What does git pull -- recurse submodules do?

git submodule foreach git pull origin master or git pull origin master --recurse-submodules is what you want if you intend to update each submodule to the latest from their origin repositories. Only then will you get pending changes in the parent repo with updated revision hashes for submodules.


1 Answers

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.

like image 109
Alim Giray Aytar Avatar answered Sep 27 '22 22:09

Alim Giray Aytar