簡體   English   中英

Git 將包含所有子模塊的存儲庫鏡像到另一個存儲庫

[英]Git mirroring a repo with all submodules to another repo

我使用以下命令將https://github.com/boostorg/boost.git鏡像到我自己的存儲庫:

git clone --recursive https://github.com/boostorg/boost.git
cd boost
git push --mirror 'URLOfMyOwnRepo'

為了鏡像所有子模塊。 然而,它並沒有像我預期的那樣工作。

基本上我想要做的是 N 對 1 鏡像,所以我可以在不同的分支/標簽中查看我自己的 repo 的源代碼

我試過:

git clone --mirror --recursive

git submodule init git submodule sync git submodule update --init --recursive

即使我在本地機器上獲得了這些子模塊,我仍然無法將它們鏡像到我的存儲庫。

此場景適用於 Boost 庫:

不要引用我的話,但我認為這是歷史性的。 回到有 SVN 的時代,我依稀記得這些庫是通過symlink 鏈接的 今天的分層布局只是所有庫都駐留在https://github.com/boostorg/下,並作為https://github.com/boostorg/boost/ 中的子模塊實現。 您可以通過查看 .gitmodules 來了解這一點:

url = ../smart_ptr.git
url = ../accumulators.git

等等 這映射到

boost -> https://github.com/boostorg/boost/
    [submodule "smart_ptr"] in libs/smart_ptr via https://github.com/boostorg/boost/../smart_ptr.git
boost -> https://github.com/boostorg/boost/
    [submodule "accumulators"] in libs/accumulators via https://github.com/boostorg/boost/../accumulators.git

您唯一需要做的就是以相同的方式設置您的本地鏡像存儲庫。 當然,還有像"numeric_conversion""disjoint_sets""ublas"這樣的流浪貓,它們映射到libs/numeric或其他目錄。 總之,這在未來可能會改變。

我采用了neonTTY的方法並針對我的用例對其進行了修改,修復了“損壞的引用”。 我將它用於本地 gentoo ebuild 惡作劇。

變化:

代碼:

#!/bin/bash
# Replicate a local copy of the boost git repositories.
# The current pwd is the root for the hierarchy of boost repositories
# from https://github.com/boostorg/ and https://github.com/boostorg/boost.git
# is the root of your local boost mirror.
# Jedzia (p) 2020, EvePanix 
# based on neonTTY's script via 
# https://stackoverflow.com/a/55856059/1530424 on Apr 25 '19

git clone https://github.com/boostorg/boost.git boost.git

cd boost.git
git submodule status | awk '{print $2}' > ../boost_git_submodules_list.txt
cd ..
while read line; do
    module=`cut -d'/' -f2 <<< $line`

    if [ $module == *"libs/numeric"* ] || [ $module == "numeric" ]; then
      echo "skip $module.git"
    else
      echo "git clone https://github.com/boostorg/$module.git"
      git clone https://github.com/boostorg/$module.git $module.git
    fi
done < boost_git_submodules_list.txt

git clone https://github.com/boostorg/numeric_conversion.git numeric_conversion.git
git clone https://github.com/boostorg/interval.git interval.git
git clone https://github.com/boostorg/odeint.git odeint.git
git clone https://github.com/boostorg/ublas.git ublas.git

git clone https://github.com/boostorg/disjoint_sets.git disjoint_sets.git

之后,您可以簡單地運行git clone --recursive /path/where/you/started/the/script/boost.git並正確引用子模塊。

PS:順便說一句。 為什么這對 OP (@zdunker) 不起作用是因為您沒有對boost.git根目錄的寫訪問權限。 這是沒有意義的,因為您希望自己擁有一個子模塊存儲庫的深層副本。 因此,您還需要將子模塊作為本地副本。 不幸的是,這也給您帶來了跟蹤所有更改的負擔,包括您的和來自上游的更改。 歡迎來到存儲庫維護者的生活:) 使用良好的文檔並准確無誤,尤其是當您在不同位置進行的不僅僅是簡單的更改時。 這很快就會變得多毛和混亂。

我剛剛經歷了同樣的經歷,並在從 github 遞歸克隆 boost 后陷入困境。

最后,我創建了以下 bash 腳本以跳轉到每個子模塊文件夾並手動將鏡像推送到我的私人 gitlab 存儲庫。 然后,當我嘗試從我的私人 gitlab 進行 git 克隆時,主存儲庫似乎在它們的新 url 中找到了沒有任何其他配置的每個子模塊。

#!/bin/bash
# This file is meant to help a user mirror the submodule-rich github repo 'boost' on our private gitlab
# start in boost root directory of boost cloned with:
# git clone --recursive https://github.com/boostorg/boost.git

myhost=example.com

git submodule status | awk '{print $2}' > boost_git_submodules_list.txt
while read line; do
    cd $line
    module=`cut -d'/' -f2 <<< $line`
    echo "git push --mirror git@$myhost:boostorg/$module.git"
    git push --mirror git@$myhost:boostorg/$module.git
    cd -
done < boost_git_submodules_list.txt

這需要一段時間,並且在他們推送時有一些損壞的引用,但我希望這會有所幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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