User Tools

Site Tools


library:git:generalcmd

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
library:git:generalcmd [2023/01/19 13:57]
lhaosen
library:git:generalcmd [2023/01/28 14:20]
lhaosen [1.6 删除子模块]
Line 281: Line 281:
   gitdir: ../../.git/modules/<color #ed1c24>app/pm2</color>   gitdir: ../../.git/modules/<color #ed1c24>app/pm2</color>
  
-==== - 从已有的文件创建 git 子模块 ==== 
  
-  * 为sub-module创建一个单独的 git仓库+==== - 查看所有子模块 ==== 
 +  git submodule 
 + 
 + 
 +==== - 克隆一个带子模块的仓库 ==== 
 + 
 +  - 下载主项目: git clone <remote-URL> 
 +  - git submodule init 
 +  - git submodule update 
 +  - 更新子模块: (在子模块目录) git pull origin master 
 + 
 +注: 
 +  * git submodule init  git submodule update 两条指令可以合并为: git submodule update --init --recursive 
 +  * git submodule init 的作用就是将子模块的信息写到 .git/config中 
 +  * git submodule update 的作用是将子模块的空目录 clone 成对应版本的 git 仓库。 
 +  * 当目录为空时,git submodule 显示的子模块不带版本信息。 
 + 
 + 
 + 
 +==== - 主仓库添加子模块(已存在的git仓库) ==== 
 +  git sumodule add <remote-URL> [name] 
 +  git add name 
 +  git commit -m "add submodule" 
 +  git push origin master 
 + 
 + 
 + 
 + 
 +==== - 主仓库添加子模块(将已有的目录设为子模块)==== 
 + 
 +  * 为sub-module创建一个单独的git仓库
  
   git checkout v2.0   git checkout v2.0
Line 304: Line 333:
   git submodule add https://github.com/bitmingw/sub-module.git   git submodule add https://github.com/bitmingw/sub-module.git
   git commit -m "add submodule version 1.0"   git commit -m "add submodule version 1.0"
 +
 +==== - 删除子模块 ====
 +  * 逆初始化模块,其中{MOD_NAME}为模块目录,执行后可发现模块目录被清空
 +
 +   git submodule deinit <Submodule>
 +
 +  * 删除.gitmodules中记录的模块信息(--cached选项清除.git/modules中的缓存)
 +
 +  git rm --cached <Submodule>
 +
 +  * 提交更改到代码库,可观察到'.gitmodules'内容发生变更
 +
 +  git commit -am "Remove a submodule." 
  
 ==== - 向下同步子模块仓库 ==== ==== - 向下同步子模块仓库 ====
Line 312: Line 354:
      
      
-==== 查看所有子模块 ==== 
-  git submodule 
  
  
  
library/git/generalcmd.txt · Last modified: 2023/02/16 17:13 by lhaosen