设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 数据 手机
当前位置: 首页 > 服务器 > 安全 > 正文

Git Submodule使用完整教程(小结)(15)

发布时间:2020-08-21 01:42 所属栏目:53 来源:网络整理
导读:henryyan@hy-hp ~/submd/ws/project1-b git:(master) git add bin/update-submodules.sh henryyan@hy-hp ~/submd/ws/project1-b git:(master) git commit -m "添加自动更新submodule的快捷脚本^_^"[master 756e788]

➜ henryyan@hy-hp ~/submd/ws/project1-b git:(master) ✗ git add bin/update-submodules.sh ➜ henryyan@hy-hp ~/submd/ws/project1-b git:(master) ✗ git commit -m "添加自动更新submodule的快捷脚本^_^" [master 756e788] 添加自动更新submodule的快捷脚本^_^ 1 files changed, 9 insertions(+), 0 deletions(-) create mode 100755 bin/update-submodules.sh ➜ henryyan@hy-hp ~/submd/ws/project1-b git:(master) git push Counting objects: 5, done. Delta compression using up to 2 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (4/4), 625 bytes, done. Total 4 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (4/4), done. To /home/henryyan/submd/ws/../repos/project1.git 8fcca50..756e788 master -> master

2.9 新进员工加入团队,一次性Clone项目和Submodules

一般人使用的时候都是使用如下命令:

git clone /path/to/repos/foo.git git submodule init git submodule update

新员工不耐烦了,嘴上不说但是心里想:怎么那么麻烦?

上面的命令简直弱暴了,直接一行命令搞定:

git clone --recursive /path/to/repos/foo.git

–recursive参数的含义:可以在clone项目时同时clone关联的submodules。

git help 对其解释:

--recursive, --recurse-submodules
   After the clone is created, initialize all submodules within, using their default settings. This is equivalent to running git
   submodule update --init --recursive immediately after the clone is finished. This option is ignored if the cloned repository
   does not have a worktree/checkout (i.e. if any of --no-checkout/-n, --bare, or --mirror is given)

2.9.1 使用一键方式克隆project2

➜ henryyan@hy-hp ~/submd/ws git clone --recursive ../repos/project2.git project2-auto-clone-submodules Cloning into project2-auto-clone-submodules... done. Submodule 'libs/lib1' (/home/henryyan/submd/repos/lib1.git) registered for path 'libs/lib1' Submodule 'libs/lib2' (/home/henryyan/submd/repos/lib2.git) registered for path 'libs/lib2' Cloning into libs/lib1... done. Submodule path 'libs/lib1': checked out '8c666d86531513dd1aebdf235f142adbac72c035' Cloning into libs/lib2... done. Submodule path 'libs/lib2': checked out 'e372b21dffa611802c282278ec916b5418acebc2' 舒服……

3.移除Submodule

牢骚:搞不明白为什么git不设计一个类似:git submodule remove的命令呢?

我们从project1.git克隆一个项目用来练习移除submodule:

➜ henryyan@hy-hp ~/submd/ws git clone --recursive ../repos/project1.git project1-remove-submodules Cloning into project1-remove-submodules... done. Submodule 'libs/lib1' (/home/henryyan/submd/repos/lib1.git) registered for path 'libs/lib1' Submodule 'libs/lib2' (/home/henryyan/submd/repos/lib2.git) registered for path 'libs/lib2' Cloning into libs/lib1... done. Submodule path 'libs/lib1': checked out '8c666d86531513dd1aebdf235f142adbac72c035' Cloning into libs/lib2... done. Submodule path 'libs/lib2': checked out 'e372b21dffa611802c282278ec916b5418acebc2' ➜ henryyan@hy-hp ~/submd/ws cd !$ ➜ henryyan@hy-hp ~/submd/ws cd project1-remove-submodules

3.1 Step by

1、删除git cache和物理文件夹

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读