「Git」submodule使用入门
来源:互联网 发布:怎样破解公司网络限制 编辑:程序博客网 时间:2024/05/15 10:33
开发过程中经常用到的Git操作在这篇博客Git常用命令大集合有介绍,但是没有涉及到submodule的命令,这也是比较常用的命令,这篇博客就介绍下git submodule的用法.
开发过程中,经常会有一些通用的部分希望抽取出来做成一个公共库来提供给别的工程来使用,而公共代码库的版本管理是个麻烦的事情。而且一旦更新了就要同步到多个引用的系统中,这个时候使用git submodule,然后执行: git submodule update就全部搞定了。
下面就以Android开发为例,讲述下submodule的具体用法。
假设一个Android Demo的目录是这样的:app, extras。其中app是程序的主要目录,extras目录是引用的一些library, 比如程序中引用了volley的library.
添加
为当前工程添加submodule,命令如下:
git submodule add 仓库地址路径即\
git submodule add https://android.googlesource.com/platform/frameworks/volleyextras
命令执行完成,会在当前工程根路径下生成一个名为”.gitmodules”的文件,其中记录了子模块的信息。添加完成以后,再将子模块所在的文件夹添加到工程中即可。
更新
如果过了一段时间volley库有更新,这时候我们的app也需要更新,命令如下:
git submodule update
git submodule foreach git pull\
git submodule foreach –recursive git submodule init\
git submodule foreach –recursive git submodule update
==
删除
1.删除.gitsubmodule中对应submodule的条目
2.删除.git/config 中对应submodule的条目
3.执行git **rm –cached {**submodule**_path}。注意,路径不要加后面的”/”。例如:你的**submodule保存在 supports/libs/websocket/ 目录。执行命令为:**git **rm –cached supports/libs/websocket
4. 删除对应的目录: rm -rf supports/libs/websocket
更新URL
1.更新 .gitsubmodule中对应submodule的条目URL
2.更新.git/config 中对应submodule的条目的URL
3.执行**git ****submodule **sync
下载的工程带有submodule
当使用git clone下来的工程中带有submodule时,初始的时候,submodule的内容并不会自动下载下来的,此时,只需执行如下命令:
git submodule update –init –recursive
即可将子模块内容下载下来后工程才不会缺少相应的文件。
- 「Git」submodule使用入门
- git submodule的使用
- git submodule的使用
- git submodule的使用
- git submodule的使用
- git submodule的使用
- git submodule 实际使用
- git submodule的使用
- git submodule的使用
- git submodule的使用
- git submodule的使用
- Git Submodule 使用简介
- git submodule的使用
- Git Submodule 使用简介
- git submodule的使用
- Git Submodule 使用简介
- git submodule的使用
- git submodule的使用
- 反转链表
- Maven学习笔记(待完善)
- 「Git」多账号多SSH-KEY使用教程
- 「Git」合并多个 Commit
- JSP自定义标签开发入门(转)
- 「Git」submodule使用入门
- SourceTree 免登录跳过初始设置
- .gitignore忽略了文件,每次提交还是会变更这个文件的解决方法
- 「Git」merge –squash介绍
- 微信网页开发weixin://preInjectJSBridge/fail、分享描述失效问题记录
- java中分代思想
- The repository for this project is empty 解决方法
- spring_SSH整合之_Struts2_Spring_Plugin的详解
- CSS中margin和padding的区别