Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to checkout git submodule path

I have a problem when working with git submodules.

Whenever i receive a new submodule reference from the upstream repository, executing git submodule update gives the following result:

fatal: reference is not a tree: dd208d46ecdd1ac0d2b2594a610fe4c9150fece1 Unable to checkout 'dd208d46ecdd1ac0d2b2594a610fe4c9150fece1' in submodule path 'submodule/path' 

It is important to note that the submodule has several remotes, of which the upstream remote should be used to update the submodule reference tree. I'm guessing that my problem is there, but i am not sure.

My setup is the following:

Git project

Remotes:

  1. origin (my git fork)
  2. upstream (project repo)

Submodule "module", has remotes:

  1. origin (my git fork)
  2. upstream (project repo)

Does anyone know what is causing my problem?

like image 440
Richard Tuin Avatar asked Feb 08 '13 08:02

Richard Tuin


People also ask

How do I change the path of a submodule?

gitmodules and change the path of the submodule appropriately, and put it in the index with git add . gitmodules . If needed, create the parent directory of the new location of the submodule ( mkdir -p new/path/to ). Move all content from the old to the new directory ( mv -vi old/path/to/module new/path/to/submodule ).

How do I add a submodule to a specific path?

In order to add a Git submodule, use the “git submodule add” command and specify the URL of the Git remote repository to be included as a submodule. When adding a Git submodule, your submodule will be staged. As a consequence, you will need to commit your submodule by using the “git commit” command.

What is path to submodule?

A submodule can be located anywhere in a parent Git repository's working directory and is configured via a . gitmodules file located at the root of the parent repository. This file contains which paths are submodules and what URL should be used when cloning and fetching for that submodule.

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 .


1 Answers

When doing git submodule update, git tries to checkout the commit/tree which is saved in the super project (in your example, the one with commit id dd208d4...)

I think you get the error because within the submodule there no such object present. You have to make sure that it is there. Usually that means that you have to fetch/pull it from a remote first.

Probably you have to

git submodule foreach git fetch git submodule update 

or maybe

git fetch --recurse-submodules 

Assuming, that the submodule is configured, so that it can fetch the missing commit from the remote origin. In the end, you must know, from where you can fetch the missing commit and you have to get it.

You could check, whether you have dd208d4... by doing something like:

cd ./module git log dd208d46ecdd1ac0d2b2594a610fe4c9150fece1 git cat-file -p dd208d46ecdd1ac0d2b2594a610fe4c9150fece1 git ls-tree dd208d46ecdd1ac0d2b2594a610fe4c9150fece1 

One possible cause for such a problem is, that the one who published the new commit from the super module, did not publish the necessary commits from the submodule. He has to publish the commits from the submodule first.

like image 83
thaller Avatar answered Sep 28 '22 10:09

thaller