菜单开关

周梦康 发表于 2018-01-03 1246 次浏览 标签 : git

https://havee.me/linux/2012-06/the-git-advanced-submodule.html

添加

git submodule add <url> <path>
git submodule add git@gitlab.mengkang.net:mengkang.zmk/yq.git yq_new_framework
Cloning into '/Users/mengkang/PhpstormProjects/xx/yq_new_framework'...
remote: Counting objects: 2881, done.
remote: Total 2881 (delta 497), reused 2131 (delta 497)
Receiving objects: 100% (2881/2881), 1.65 MiB | 1.83 MiB/s, done.
Resolving deltas: 100% (497/497), done.

变化

  1. 我们发现项目根目录下多了一个yq_new_framework的目录
  2. .gitmodules内容有变化
[submodule "yq_new_framework"]
    path = yq_new_framework
    url = git@mengkang.net:mengkang.zmk/yq.git

切换子模块的分支

$ git config -f .gitmodules submodule.yq_new_framework.branch develop
$ cat .gitmodules
[submodule "yq_new_framework"]
    path = yq_new_framework
    url = git@gitlab.alibaba-inc.com:mengkang.zmk/yq.git
    branch = develop

进入子模块目录,切换分支之后,更新。

$ git checkout -b develop
$ git pull origin develop

删除 submodule

$ git rm --cached yq_new_framework
rm 'yq_new_framework'
$ ls|grep yq_new
yq_new_framework
$ rm -rf yq_new_framework
$ vim .gitmodules
$ vim .git/config
$ git commit -a -m '删除新框架子模块的引入方法'
[feature/20190115_3461506_new_framework_1 1ae63268] 删除新框架子模块的引入方法
 2 files changed, 5 deletions(-)
 delete mode 160000 yq_new_framework
$ git push
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 340 bytes | 340.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)

评论列表