git submodule新增 更新和刪除

2022-01-10 00:54:19 字數 1318 閱讀 6952

git submodule add
path:要存放的本地路徑

執行新增命令成功後,可以在當前路徑中看到乙個.gitsubmodule檔案,裡面的內容就是我們剛剛add的內容

如果在新增子模組的時候想要指定分支,可以利用 -b 引數

git submodule add -b 

git submodule add  3rdparty/benchmarks
.gitsubmodule內容

[submodule "3rdparty/benchmarks"]

path = 3rdparty/benchmarks

url =

git submodule add -b cnn_tf_v1.10_compatible  3rdparty/benchmarks
.gitsubmodule內容

[submodule "3rdparty/benchmarks"]

path = 3rdparty/benchmarks

url =

branch = cnn_tf_v1.10_compatible

當我們add子模組之後,會發現資料夾下沒有任何內容。這個時候我們需要再執行下面的指令新增原始碼。

git submodule update --init --recursive
這個命令是下面兩條命令的合併版本

git submodule init

git submodule update

我們引入了別人的倉庫之後,如果該倉庫作者進行了更新,我們需要手動進行更新。即進入子模組後,執行

git pull
進行更新。

刪除子模組目錄及原始碼

rm -rf 子模組目錄
刪除.gitmodules中的對應子模組內容

vi .gitmodules
刪除.git/config配置中的對應子模組內容

vi .git/config
刪除.git/modules/下對應子模組目錄

rm -rf .git/modules/子模組目錄
刪除git索引中的對應子模組

git rm --cached 子模組目錄

Git submodule 命令簡介

摘要 在.git config和.gitmodules中記錄的子模組倉庫的遠端位址和路徑,然後使用乙個特殊的模式為160000的檔案來記錄子模組倉庫當前的commit id git submodule add origin submd repos lib2.git libs lib2 新增遠端ori...

git submodule使用記錄

首先建立乙個子模組倉庫 當做公共元件模組son 然後在現有的專案 p1,p2 中使用 git submodule add git位址當更新p1中son的東西時候,需要在p1中son目錄裡提交,p1直接提交會報 所以需要單獨進入專案中提交子模組 1.採用遞迴方式一次性轉殖所有 git clone 位址...

git submodule 子模組使用

當我們的git專案需要引入第三方專案 另外乙個git專案 時,可以用submodule。git submodule add third party hiredis third party hiredis 是自定義路徑 hiredis必須不存在。新增成功之後可以看到 third party hired...