簡體   English   中英

將 git 個子模塊從一個倉庫復制到另一個倉庫

[英]Copy git submodules from one repo to another

我正在開發一組依賴於一組通用的其他庫的庫。

我想將 .gitsubmodules 文件從一個包含所有必要子模塊的存儲庫復制到所有其他存儲庫中。

但是我似乎無法讓 git 識別子模塊文件,或者以其他方式將子模塊拉入新存儲庫。

Git 需要兩件事來實現一個子模塊:

  1. 來自.gitmodules文件的配置,以及
  2. 索引中的相應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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM