GitHub真是個開源大寶庫,不只能學習代碼,還能學習git的使用!
最近在研究Off-the-Record-iOS項目(https://github.com/chrisballinger/Off-the-Record-iOS)時,學習實踐了gitsubmodule的用法!
這個項目中有一個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’
這文章總結的太好了!!