Unable to checkout git submodule path
Asked Answered
F

9

38

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?

Farrish answered 8/2, 2013 at 8:29 Comment(0)
F
43

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.

Frias answered 8/2, 2013 at 16:19 Comment(2)
Submodule commits are published, problem still occurs.Ivaivah
Adding to the long list of things I have to do before rebaseing a feature branch onto an updated master to undo accidental changes to a submodule… so far it's git submodule foreach git fetch && git submodule deinit -f . && git submodule update --init.Deledda
J
7

Make sure that the submodules were pushed

cd submodule-dir
git push

In my case, I had:

  • committed to the submodule
  • not pushed
  • committed to the parent with the updated submodules
  • pushed the parent

so it is no wonder that it could not be found.

Then, if you are using a web interface such as GitHub, you can also go to the submodule repository web page, and double check that the commit you need shows there.

push.recurseSubmodules on-demand

It is possible to automate pushes further with:

git push --recurse-submodules=on-demand

which also pushes submodules as needed, or starting with 2.7:

git config push.recurseSubmodules on-demand
git push
Jacobi answered 22/8, 2014 at 12:16 Comment(3)
Essentially the same answer as previously, but this problem still occurs sometimes even when it is pushed.Ivaivah
@Nuzzolilo can you generate a minimal reproducible local example, e.g. mkdir repo && cd repo && git init && touch a && git add . ...Jacobi
See github.com/projectkudu/kudu/issues/1972 - Can happen with submodules that are accessed via a deploy key on Github. Sorry, do not have time to do more than thatIvaivah
S
1

I had the same problem and I resolved adding a new commit for parent project and push allCheck the Subproject commit and commit from your module

Studio answered 29/8, 2014 at 13:26 Comment(0)
R
1

My issue was I had uncommitted changes in the submodules in their build.gradle files (which I think were automatically changed). They showed up in the git diff. I just did git checkout . to reset the submodule repos to have no changes and then the git submodule update worked.

Reimport answered 8/3, 2017 at 18:2 Comment(0)
C
0

My issue is that upon a cat .gitmodules of my repo, I was pointing at the wrong remote for the submodule's repo (I had originally cloned it with the original remote, but then switched to a fork of it; the gitmodules file never updated to reflect the change).

Cachet answered 27/9, 2016 at 16:38 Comment(0)
G
0

just saw this problem when i forgot to push the changes in one of my submodules

make sure changes are pushed

Gobang answered 5/9, 2017 at 19:32 Comment(0)
F
0

Another way could be, without the command line git options, but to do this manually. The scenario happens mostly, when the sub-module paths have been moved/replaced (but not properly), thereby still pointing to the old references in the locally checkout repositories.

1) Locate the repository, and the submodule

ls -la .git/modules
   rm -f .git/modules/<module-with-issue>

2) Remove the older local sub-module configurations

 gedit .git/config

(remove the sub-module url entry here)

It looks something like this;

 *[submodule "module-with-issue"]
       url = ...*

3) Now, fetch and update the submodules freshly git fetch git submodule update --recursive --init

Note: One may additionally have to remove, the locally checked-out submodule folder in your repository, before attempting submodule update.

Frenulum answered 21/8, 2018 at 5:0 Comment(0)
A
0

Adding git rm --cached <submodule-directory> helps me on gitlab:

.prepare_deploy: &prepare_deploy
  before_script:
    - bundle install -j $(nproc) --path vendor
    - which ssh-agent || (apt-get update -y && apt-get install openssh-client -y)
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - eval $(ssh-agent -s)
    - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
    - (echo "$SSH_PRIVATE_KEY" | base64 --decode) > ~/.ssh/id_rsa
    - chmod 600 ~/.ssh/id_rsa
    - git rm --cached <submodule-directory>
    - git submodule sync --recursive
    - git submodule update --init --recursive
Abecedarium answered 27/3, 2019 at 8:31 Comment(0)
E
0
git submodule unable to checkout

Note:

You may need to check if your remote branch is Case Sensitive. eg: IB_Certs, but you are using ib_certs

I found that issue, and took a long time to find why, at last, I found it case sensitive.

Hopefully, this solves your problems.

Eliseo answered 11/4, 2022 at 5:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.