我想克隆一个git repo [1],它有一个在.gitmodules中定义的子模块:
[submodule "PointInCircle"]
path = PointInCircle
url = https://github.com/midas-journal/midas-journal-843
根据这些问题[2-4],我试过:
$git clone --recursive https://github.com/midas-journal/midas-journal-851
如果我理解正确的子模块,我显然没有,那么midas-journal-851里面应该有一个叫做PointInCircle的目录,第二个repo克隆到它里面.但是,没有创建PointInCircle目录,据我所知,代码没有被克隆到任何地方.为了好的衡量,我也试过……
$git submodule init
$git submodule update
…以及…
$git submodule update --init --recursive
…和…
$git submodule foreach --recursive git submodule update --init
…在克隆目录中.每个命令都运行而不向控制台打印任何内容,我看不到目录中的任何更改.
我有什么想法我做错了吗?
[1] https://github.com/midas-journal/midas-journal-851
[2] Cloning a git repo with all submodules
[3] How to `git clone` including submodules?
[4] ‘git submodule update –init –recursive’ VS ‘git submodule foreach –recursive git submodule update –init’
最佳答案
Any ideas what I’m doing wrong?
你没有做错任何事.该存储库的子模块仅部分配置.
Submodules are defined by two things:
Submodules are composed from a so-called
gitlink
tree entry in the main repository that refers to a particular commit object within the inner repository that is completely separate. A record in the.gitmodules
… file at the root of the source tree assigns a logical name to the submodule and describes the default URL the submodule shall be cloned from.
此存储库包含.gitmodules文件,但不包含gitlink对象.
GitHub displays proper submodules with a grey folder icon,此存储库中不存在:
由于错误的.gitmodules文件只包含一个条目,我建议你这样做
>删除.gitmodules文件,
git rm .gitmodules
>正确添加子模块,
git submodule add https://github.com/midas-journal/midas-journal-843 PointInCircle
>并承诺.
git commit -m "Fix PointInCircle submodule"
git commit的输出应显示PointInCircle添加模式160000(表示gitlink),现在应该正确配置您的存储库.使用git子模块状态可以确定:
$git submodule status
9bc2651367f8cc5f47ac5f6c708db2f9a71d8fd8 PointInCircle (heads/master)
您可能希望使用修复程序向父存储库打开拉取请求,但由于它仅包含三年前的单个提交,因此我怀疑它已被放弃.