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.
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 .
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 .
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 .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With