Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git submodule update fails with error on one machine but works on another machine

I created a git submodule and pushed it onto our main repository. This worked fine and I can see the submodule in the repository via a browser.

To test it I tried to get the source in a fresh build tree. First I ran git submodule init and then git submodule update <submodule-name>.

The second command failed with error:

error: pathspec 'x/mypkg' did not match any file(s) known to git. Did you forget to 'git add'

I tried adding to .gitmodules the url to the submodule but with no luck.

like image 775
SeattleOrBayArea Avatar asked Jan 13 '12 00:01

SeattleOrBayArea


People also ask

Do submodules update automatically?

Submodules are very static and only track specific commits. Submodules do not track git refs or branches and are not automatically updated when the host repository is updated.

How can I update one submodule?

By adding the submodule. <name>. update config setting, you ensure that the selective clone of the submodule will be followed by an update, only for that submodule.

What is git submodule update -- init -- recursive?

git submodule update --init --recursive --remote - updates all submodules recursively along their tracking branches. Without the --remote , it'll reset the submodule working directories to the "right" commit for the parent.


2 Answers

I also received this error using TortoiseGit while trying to update submodules that aren't in the index. That is, they exist in .gitmodules but have not been correctly added to the repository.

The solution is to manually re-add them using the paths specified in .gitmodules. You can use the TortoiseGit UI or run this on the command line for each module...

git submodule add <url> <path>

Re-adding a git submodule

(I realise this is probably not the solution for the original poster, but hopefully it helps others Googling this.)

like image 80
Simon East Avatar answered Sep 21 '22 08:09

Simon East


This is likely because you or someone on your team has changes in your submodule that are unpublished (committed, but not pushed to the remote server). They then published the superproject with references to the git commit in the submodule which does not exist on the git server. So git is trying to pull down a specific submodule git commit ID that it can't find.

This would be the case if the changes are in a repository elsewhere on your machine or on another machine.

To resolve, go to that repository that references that commit and publish (push) the submodule changes to the server. Or change the submodule to point to a different commit ID.

like image 44
Highway of Life Avatar answered Sep 18 '22 08:09

Highway of Life