Git submodule子模組的使用

2021-10-08 17:32:11 字數 1450 閱讀 5052

在專案中的.gitmodules檔案中檢視當前submodule設定

git clone  --recursive #遞迴的方式轉殖整個專案

git submodule add

#新增子模組

#示例:git submodule add git: findername

git submodule init #初始化子模組

git submodule update --init --recursive #初始化並更新子模組

git submodule foreach git pull #拉取所有子模組

git pull --recurse-submodules #拉取所有子模組中的依賴項

git submodule sync

#將新的url同步更新,該步驟適用於git submodule add或修改.gitmodules檔案之後

git submodule status third_party/modulea #檢視子模組狀態,即該子模組切入的提交節點位置,即某hash值

#刪除子模組,然後刪除對應資源庫所有檔案

gitrm --cached modulea

rm -rf modulea

git submodule set-url third_party/modulea #,更新子模組url,該功能在1.8.3.1以上版本

git submodule set-branch --branch dev third_party/modulea #設定子模組專案採用的分支,該功能在1.8.3.1以上版本

若希望每次clone拉取新的submodule到指定分支指定節點,需要在提交時將子模組checkout到指定指標位置,然後提交該子模組所在目錄git add third_party/modulea;git commit ***;(其實是提交子模組中的.git所在commit指標中位置hash值e6fd72ad).

fatal: 引用不是乙個樹:a27a43eafa8f4dd514e89984f5394260a36ea4f6

無法在子模組路徑 『src/lib/ecl』 中檢出 『a27a43eafa8f4dd514e89984f5394260a36ea4f6』

#解決方法為git新增子模組的位置:

git add src/lib/ecl

git submodule update --init --recursive

fatal: needed a single revision

將出錯的資料夾刪除後,重新執行git submodule update命令

#雖然優化,但是沒有優化刪除快取中庫

gitrm --cached boringssl

參考文章 git submodule的使用

參考文章 git submodule管理專案子模組

git submodule 子模組使用

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

Git Submodule 管理專案子模組

1 新增乙個子模組 git submodule add 子模組位址 自定義到當前工程的路徑 git commit git push 2 轉殖 更新帶子模組的工程 2.1 方法一 git clone 工程位址,進入工程後 git submodule init init 操作只需要在剛clone下來時執...

Git Submodule管理專案子模組

當專案越來越龐大之後,不可避免的要拆分成多個子模組,我們希望各個子模組有獨立的版本管理,並且由專門的人去維護,這時候我們就要用到git的submodule功能。git clone recursive 遞迴的方式轉殖整個專案 git submodule add 新增子模組 git submodule ...