github克隆项目中的子模块submodule时遇到的问题

GitHub真是个开源大宝库,不只能学习代码,还能学习git的使用!

最近在研究Off-the-Record-iOS项目(https://github.com/chrisballinger/Off-the-Record-iOS)时,学习实践了git submodule的用法!

这个项目中有一个Submodules文件夹,包含了该项目所引用到的其他GitHub上的开源项目,最开始没注意到,直接Download ZIP拿下来的,发现XCode项目中一堆红色文件名,才发现原来还有很多依赖项目,仔细看了一下还挺不少,于是果断放弃手动挨个下载…

搜索了一下,发现项目的issue #87有人问到了类似的问题:https://github.com/chrisballinger/Off-the-Record-iOS/issues/87,按照下面的回答,重新git clone了项目,并使用git submodule init && git submodule update(1.6以后版本也可以直接用git clone –recursive代替)来更新项目中的依赖子模块,更了前几个之后又出现了新的错误:

Submodule path ‘Submodules/DAKeyboardControl’: checked out ‘5352d1ff2d1131d974d94406ed8fcf8eb068aa72’
Cloning into ‘Submodules/LibOrange’…
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Clone of ‘git@github.com:ChatSecure/LibOrange.git’ into submodule path ‘Submodules/LibOrange’ failed

这个issue #105也提到了:https://github.com/chrisballinger/Off-the-Record-iOS/issues/105,根据作者的回答,需要更新对应项的git url,替换为https方式!

于是进入项目根目录,vi .gitmodules,编辑文件,找到提示问题的模块LibOrange,修改url = git@github.com:ChatSecure/LibOrange.git为url = https://github.com/ChatSecure/LibOrange.git,:wq保存退出。

修改好模块url后还是不能直接更新,经过几次尝试,发现需要重新同步子模块的url,执行git submodule sync,刷新url,然后再次执行git submodule update –init,这样又会提示:

fatal: Needed a single revision
Unable to find current revision in submodule path ‘Submodules/LibOrange’

这个问题参考这里:http://blog.csdn.net/frank2336/article/details/7414545,解决方法时rm -rf LibOrange删掉已存在的文件夹。

删除后,返回项目根目录,再次执行git submodule update –init就不再有问题了:

remote: Counting objects: 1052, done.
remote: Compressing objects: 100% (547/547), done.
remote: Total 1052 (delta 439), reused 1050 (delta 438)
Receiving objects: 100% (1052/1052), 3.96 MiB | 46 KiB/s, done.
Resolving deltas: 100% (439/439), done.
From https://github.com/ChatSecure/LibOrange
* branch HEAD -> FETCH_HEAD
Submodule path ‘Submodules/LibOrange’: checked out ‘d7ae559dfebe2eb6cc3996735fa6081e1aaa02fa’

博主友情提示:

如您在评论中需要提及如QQ号、电子邮件地址或其他隐私敏感信息,欢迎使用>>博主专用加密工具v3<<处理后发布,原文只有博主可以看到。