项目submodule子模块管理

1、在git上创建space,将子模块上传上去,然后复制git地址

一:添加submodule:

git submodule add $giturl $foldername

其中giturl表示git仓库地址,foldername表示submodule的目录名,例如:
git submodule add git://github.com/xx/A.git A
注:下面示例全部以 A 当做submodule所在目录
完成后,将文件变化提交即可。

命令执行完成,会在当前工程根路径下生成一个名为".gitmodules"的文件,其中记录了子模块的信息。添加完成以后,再将子模块所在的文件夹添加到工程中即可。

二:删除submodule:
通过 git rm 删除子模块,删除命令如下

git rm -f submodule_name         #同时删除本地文件

git rm --cached submodule_name   #保留本地文件

三:clone有submodule的git仓库

git clone $giturl
git submodule init
git submodule update

四:几个submodule都想更到最新
有个简便操作

git submodule foreach git pull

这样所有submodule都更到最新了,add commit即可。

注:
操作一个新项目关联子模块时需要注意几点:
1、git submodule add $giturl $foldername
后面的目录名称一定要记得写目录名
2、clone下来的项目一定要先git submodule init,然后git submodule update,要先init。
3、删除子模块后,重新添加报下面的错误,说明删除的不干净。

A git directory for 'formRenderLib' is found locally with remote(s):
origin git@gitlab.com:newcare/formRenderLib.git
If you want to reuse this local git directory instead of cloning again from
git@gitlab.com:newcare/formRenderLib.git
use the '--force' option. If the local git directory is not the correct repo
or you are unsure what this means choose another name with the '--name' option.

参考链接为:
https://blog.csdn.net/dongguanghuiyin/article/details/78792992

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容