Git submodule子模块
1. 子模塊的添加
git submodule add <url> <path>
其中,url為子模塊的路徑,path為該子模塊存儲的目錄路徑。
比如:
git submodule add https://github.com/openresty/echo-nginx-module.git external/echo-nginx-module
?
執(zhí)行成功后,git status會看到項目中修改了.gitmodules,并增加了一個新文件(為剛剛添加的路徑)
root@dispatch:/home/Xlon# git status On branch feature_ai_20190712 Your branch is up-to-date with 'origin/feature_ai_20190712'. Changes to be committed:(use "git reset HEAD <file>..." to unstage)modified: .gitmodulesnew file: external/echo-nginx-modulegit diff --cached查看修改內(nèi)容可以看到增加了子模塊,并且新文件下為子模塊的提交hash摘要
git commit提交即完成子模塊的添加
git push 推送到倉庫就ok了
?
2. submodule 的使用
git submodule init
git submodule update
?
3.?.gitmodules 和.git/config
Git在兩個地方存儲有關(guān)子模塊的信息。第一個是在一個名為的文件中.gitmodules,該文件被簽入git存儲庫。對此文件的更改將傳播到其他存儲庫。
另一個位置在.git/config。
當更新存儲庫時,您.gitmodules將更新文件的副本,但不會更新您的.git/config文件; 當想要從新網(wǎng)址開始簽出時,執(zhí)行g(shù)it submodule sync以將新配置從中復(fù)制.gitmodules到.git/config。
?
?
重點:
刪除Submodule
git?并不支持直接刪除Submodule需要手動刪除對應(yīng)的文件:
cd pod-project
git rm --cached pod-library rm -rf pod-library rm .gitmodules更改git的配置文件config:
vim .git/config
可以看到Submodule的配置信息:
[submodule "pod-library"]url = git@github.com:jjz/pod-library.git刪除submodule相關(guān)的內(nèi)容,然后提交到遠程服務(wù)器:
git commit -a -m 'remove pod-library submodule'
git push branch? , 上傳到遠程分支
總結(jié)
以上是生活随笔為你收集整理的Git submodule子模块的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Ansible中文权威指南
- 下一篇: 《直播疑难杂症排查》之三:首开慢