嵌套 git repos 和子模块之间的区别 [英] Difference between nested git repos and submodules
问题描述
git 版本 - 2.6.4
我遇到了无法使用 --recursive
标志克隆完整存储库内容的情况.
I have stuck in a situation where I am not able to clone complete repo content using --recursive
flag.
我的主存储库有两个子目录 health-check
和 hellspawn
.
My main repository have two sub-directory health-check
and hellspawn
.
我已经创建了 hellspawn
作为子模块,它也在 .gitmodules
文件中有它的条目.
I have created hellspawn
as submodule and it has its entry in .gitmodules
file also.
我不确定 health-check
是什么,是 submodule
还是 nested-git
.health-check
在 .gitmodules
中没有条目,这让我觉得它可能是 nested-git
.
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
admin@admins-MacBook-Pro.local:~/try$git clone --recursive
git@github.com: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'
`
正如你看到的最后一行,如果 health-check
是嵌套的 git 那么为什么 git 正在检查 .gitmodules
文件??由于这个错误,即使在子模块 hellspawn
中,我也没有下载代码.
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.
任何帮助
推荐答案
health-check 在 .gitmodules 中没有条目,这让我觉得它可能是嵌套的 git.
health-check does not have entry in .gitmodules which make me thing it might be nested-git.
这是一个嵌套的 git 仓库.
It is a nested git repo.
如果 health-check
是嵌套的 git 那么为什么 git 在 .gitmodules
文件中检查
if
health-check
is nested git then why git is checking in.gitmodules
file
因为嵌套的 git repo 被记录为 gitlink(作为子模块),这意味着 git 检查 索引中的特殊条目 是否与 .gitmodules
文件(因为git clone
的--recursive
选项,要求克隆子模块)
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)
由于该特殊条目与任何 .gitmodules
条目路径不匹配,因此失败并显示警告.
Since that special entry does not match any .gitmodules
entry path, it fails with that warning.
由于这个错误,即使在子模块的 hellspawn 中,我也没有下载代码
Due to this error, I am not getting code downloaded even in hellspawn which is submodule
两种方法:
去掉那个特殊的条目:
尝试git rm --cached health-check
(没有尾随 '/
',正如我在git --recursive
不克隆子模块"),然后添加和推送,然后尝试git clone --recursive
再次
Get rid of that special entry:
Try andgit rm --cached health-check
(no trailing '/
', as I mentioned in "git --recursive
doesn't clone submodule"), then add and push, and then try thegit clone --recursive
again
声明子模块
即:
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)
再次添加、推送,然后再次尝试 git clone --recursive
.
Again, add, push, then try the git clone --recursive
again.
这篇关于嵌套 git repos 和子模块之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!