gpt4 book ai didi

Git 将一个包含所有子模块的 repo 镜像到另一个 repo

转载 作者:太空狗 更新时间:2023-10-29 13:46:44 30 4
gpt4 key购买 nike

我镜像了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 子模块初始化
git子模块同步
git 子模块更新 --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 即可正确引用子模块。

附言:顺便说一句。为什么这对 OP (@zdunker) 不起作用是因为您没有对 boost.git 根目录的写入权限。这是没有意义的,因为您想要自己拥有子模块存储库的深拷贝。因此,您还需要子模块作为本地副本。不幸的是,这也给您带来了跟踪所有更改的负担,包括您的更改和来自上游的更改。欢迎来到存储库维护者的生活:) 使用良好的文档并保持准确,尤其是当您在不同位置进行的不仅仅是简单的更改时。这很快就会变得复杂和困惑。

关于Git 将一个包含所有子模块的 repo 镜像到另一个 repo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37756391/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com