赞
踩
命令用法
git submodule [--quiet] [--cached]
git submodule [--quiet] add [<options>] [--] <repository> [<path>]
git submodule [--quiet] status [--cached] [--recursive] [--] [<path>…]
git submodule [--quiet] init [--] [<path>…]
git submodule [--quiet] deinit [-f|--force] (--all|[--] <path>…)
git submodule [--quiet] update [<options>] [--] [<path>…]
git submodule [--quiet] set-branch [<options>] [--] <path>
git submodule [--quiet] set-url [--] <path> <newurl>
git submodule [--quiet] summary [<options>] [--] [<path>…]
git submodule [--quiet] foreach [--recursive] <command>
git submodule [--quiet] sync [--recursive] [--] [<path>…]
git submodule [--quiet] absorbgitdirs [--] [<path>…]
实战在gitlab
上新建一个空项目,clone
到本地,然后就可以使用以下命令添加模块
#git submodule [--quiet] add [<options>] [--] <repository> [<path>]
git submodule add http://x.x.x.x/repository/test.git test
添加完成后项目目录下会新增一个.gitmodules
文件打开文件可以查看到内容如下
[submodule "test"]
path = test
url = http://x.x.x.x/myrepository/test.git
一个模块就添加好了,要是你有很多工程需要批量切换分支,管理,更新等。git-submodule
是非常好用的。
当你把所有子模块建立完成后,别人拉取到该项目,项目都为空目录,并不会拉取所有的项目文件
这个时候只需要执行以下命令即可
git submodule update --init --recursive
命令执行完成后所有项目就拉取下来了,接下来所有对项目的批量操作全部都可以使用以下命令其实就是在常规命令前加了个git submodule foreach
#git submodule [--quiet] foreach [--recursive] <command> 如
git submodule foreach git branch -a
移除子模块
git rm test
git commit -m "remove test"
git push
以上内容分清对象操作即可,概念为当前工程和工程下的子模块操作,当前工程操作还是原生git xxx
,子模块操作git submodule xxx
.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。