Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
630 views
in Technique[技术] by (71.8m points)

github - Difference between nested git repos and submodules

git version - 2.6.4

I have stuck in a situation where I am not able to clone complete repo content using --recursive flag.

My main repository have two sub-directory health-check and hellspawn.

I have created hellspawn as submodule and it has its entry in .gitmodules file also.

I am not sure what health-check is, whether a submodule or nested-git. health-check does not have entry in .gitmodules which make me thing it might be nested-git.

if so , then why am I getting git message when cloning main repository with

 [email protected]:~/try$git clone --recursive     
 [email protected]:url/mainrepo.git 

 Cloning into 'mainrepo'...
 remote: Counting objects: 28713, done.
 remote: Compressing objects: 100% (613/613), done.
 remote: Total 28713 (delta 363), reused 5 (delta 5), pack-reused 28090
 Receiving objects: 100% (28713/28713), 788.79 MiB | 3.54 MiB/s, done.
 Resolving deltas: 100% (17645/17645), done.
 Checking connectivity... done.
 Checking out files: 100% (40522/40522), done.
 No submodule mapping found in .gitmodules for path 'health-check'

`

As you can see last line if health-check is nested git then why git is checking in .gitmodules file ?? Due to this error, I am not getting code downloaded even in hellspawn which is submodule.

Any help

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

health-check does not have entry in .gitmodules which make me thing it might be nested-git.

It is a nested git repo.

if health-check is nested git then why git is checking in .gitmodules file

Because a nested git repo is recorded as a gitlink (as a submodule is), which means git checks if that special entry in the index matches one declared in the .gitmodules file (because of the --recursive option of git clone, asking to clone submodules)

Since that special entry does not match any .gitmodules entry path, it fails with that warning.

Due to this error, I am not getting code downloaded even in hellspawn which is submodule

Two approaches:

  1. Get rid of that special entry:
    Try and git rm --cached health-check (no trailing '/', as I mentioned in "git --recursive doesn't clone submodule"), then add and push, and then try the git clone --recursive again

  2. Declare the submodule

That is:

git config -f .gitmodules submodule.health-check.path health-check
git config -f .gitmodules submodule.health-check.url https://github.com/<auser>/health-check

(replace <auser> by the actual user managing that repo)

Again, add, push, then try the git clone --recursive again.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...