How to setup submodule so that git clone --recursive always takes master of submodule

两盒软妹~` 提交于 2020-01-23 12:38:40

问题


I've reference this: Git submodule head 'reference is not a tree' error

And this: git submodule tracking latest

Possibly my problem is slightly different. (I'm assuming its the same but not doing something right...)

I want my git setup such that if I run:

git clone -b master --recursive /path/to/main/repo.git

the submodules should always be cloned against "master"

Otherwise, in many cases the referenced commit doesn't exist (The branch of the submodule) or are "out of date" causing the clone to fail with error:

fatal: reference is not a tree

I've tried to setup the main repository to take the submodule master:

git submodule add -b master /path/to/submodule.git

But when cloning the main repo:

git clone -b master --recursive /path/to/main/repo.git

The submodule commit referenced doesn't exist (not taking master as expected)


回答1:


As submodule is never checked out against a branch.
It is always checked out at the SHA1 recorded by the gitlink (special entry in the index)

What you can do is:

  • making sure the submodule is set to follow the master branch
    See "How to make an existing submodule track a branch"
  • do a git submodule update --remote --recursive to make sure each submodule fetch and update themselves against their respective master branch.


来源:https://stackoverflow.com/questions/35402999/how-to-setup-submodule-so-that-git-clone-recursive-always-takes-master-of-subm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!