当前位置:   article > 正文

git-submodule 使用详解_git submodule branch

git submodule branch

命令用法

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>…​]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

实战在gitlab上新建一个空项目,clone 到本地,然后就可以使用以下命令添加模块

#git submodule [--quiet] add [<options>] [--] <repository> [<path>]
git submodule add http://x.x.x.x/repository/test.git  test
  • 1
  • 2

添加完成后项目目录下会新增一个.gitmodules文件打开文件可以查看到内容如下

[submodule "test"]
	path = test
	url = http://x.x.x.x/myrepository/test.git
  • 1
  • 2
  • 3

一个模块就添加好了,要是你有很多工程需要批量切换分支,管理,更新等。git-submodule是非常好用的。
当你把所有子模块建立完成后,别人拉取到该项目,项目都为空目录,并不会拉取所有的项目文件
这个时候只需要执行以下命令即可

git submodule update --init --recursive
  • 1

命令执行完成后所有项目就拉取下来了,接下来所有对项目的批量操作全部都可以使用以下命令其实就是在常规命令前加了个git submodule foreach

#git submodule [--quiet] foreach [--recursive] <command> 如
git submodule foreach git branch -a
  • 1
  • 2

移除子模块

git rm test
git commit -m "remove test"
git push
  • 1
  • 2
  • 3

以上内容分清对象操作即可,概念为当前工程和工程下的子模块操作,当前工程操作还是原生git xxx,子模块操作git submodule xxx.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/459337
推荐阅读
相关标签
  

闽ICP备14008679号