[英]Copy git submodules from one repo to another
我正在開發一組依賴於一組通用的其他庫的庫。
我想將 .gitsubmodules 文件從一個包含所有必要子模塊的存儲庫復制到所有其他存儲庫中。
但是我似乎無法讓 git 識別子模塊文件,或者以其他方式將子模塊拉入新存儲庫。
Git 需要兩件事來實現一個子模塊:
.gitmodules
文件的配置,以及commit
條目...您可以通過運行git submodule add
獲得。 這在文檔中是明確的,其中說明了git submodule init
命令:
通過在
.git/config
中設置submodule.$name.url
來初始化索引中記錄的子模塊(在其他地方添加和提交)。 它使用.gitmodules
中的相同設置作為模板....
實際上,這意味着您需要為每個子模塊運行git submodule add
。 如果您經常這樣做,您可以編寫一個腳本,從.gitmodules
文件中讀取子模塊配置並運行適當的git submodule add
命令。 也許是這樣的:
#!/bin/bash
submodules=( $(git config -f .gitmodules --name-only --get-regexp 'submodule\..*\.path' | cut -f2 -d.) )
for name in "${submodules[@]}"; do
path="$(git config -f .gitmodules --get submodule."$name".path)"
url="$(git config -f .gitmodules --get submodule."$name".url)"
git submodule add "$url" "$path"
done
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.