如何将git bundle与子模块一起使用?

8 git git-submodules

我正在使用git bundle来备份git存储库.在最新版本的git中,子模块的存储库元数据存储在父存储库的.git/modules中,而不是存储在子模块中的.git目录中之前.

当git-bundle在子模块中运行时,它会创建一个父repo的包,省略子模块.

谁可以解释这个?
如何制作子模块的git包?

参考: git邮件列表上的问题

编辑:

在阅读了sschuberth之后,我就编写了一个脚本来测试,并且可以验证它是否有效.我有一个备份脚本,它依赖于验证.git 目录的存在,以便知道它是否在存储库的顶级目录中,并且当子模块开始使用.git 文件时就会破坏.如果有人知道建议的方法是保证你在存储库的顶级文件夹,我很感兴趣.我不知道我是怎么错过这个的.

为了防止必须为子模块编写测试脚本的人感兴趣,这是我使用的脚本:

#!/bin/bash

git --version

mkdir super
mkdir subRemote

touch super/superFile.txt
touch subRemote/subFile.txt

cd super

   git init
   git add --all
   git commit -am"Initial commit"

cd ..


cd subRemote

   git init
   git add --all
   git commit -am"Initial commit"

cd ..


cd super

   git submodule add ../subRemote/.git
   git add --all
   git commit -am"added submodule"
   git submodule update
   echo -e "\ngit log in super:"
   git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative --all


   cd subRemote

      echo -e "\ngit bundle:"
      git bundle create ../../submoduleBundle --all --remotes

   cd ..

cd ..


git clone --mirror submoduleBundle bundledSub/.git

cd bundledSub

   git config core.bare false
   git config core.logallrefupdates true
   git remote rm origin
   git checkout

cd ..


#------------------------------------------------

cd super

   echo -e "\nfiles in super":
   ls -alh

cd ..


cd super/subRemote

   echo -e "\nfiles in super/subRemote":
   ls -alh

cd ../..


cd bundledSub

   echo -e "\nfiles in bundledSub":
   ls -alh

cd ..
Run Code Online (Sandbox Code Playgroud)

ssc*_*rth 2

您确定运行git submodule update成功并且子模块中的.git 文件(不是目录)存在吗?在我的测试中,捆​​绑子模块在 1.7.9.6 版本中工作得很好。

如果由于某种原因它仍然失败,解决方法是将子模块的存储库克隆到它自己的工作树中并git bundle从那里运行(对于git submodule status超级项目中所示的提交)。