问题
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 respectivemaster
branch.
来源:https://stackoverflow.com/questions/35402999/how-to-setup-submodule-so-that-git-clone-recursive-always-takes-master-of-subm