如何在不增加主repo大小的情况下更新浅层克隆子模块

时间:2013-12-06 22:26:34

标签: git git-submodules

我想将git转换为现有的代码库,其中包含大型二进制库文件。库文件是外部(供应商)依赖项。这些二进制文件仅用于链接最终应用程序。这些二进制文件的大小是巨大的(2.2千兆),所以为了减少主要的回购大小(而不必过度增加主回购大小),我想在git repo中托管二进制文件并使用子模块来仅引用最新版本的库二进制文件。

我可以正确设置浅子参数,但如果二进制仓库(包含完整历史记录)发生变化,我不知道如何更新到最新版本。

我拥有的回购结构与此相似:

main_project
    sub_binary
    other project files
    ...

这是允许我有一个浅子模块的命令:

cd main_project
git submodule add --depth 1 file://remote_binary_repo_path sub_binary

这样可以,并且sub_binary被固定到正确的版本。

如果更新了远程库存储库,如何更新浅子模块sub_binary(并在main_repo中记录)到最新版本(并且只有最新版本) < / p>

注意:

  • 如果我在初始子模块设置中在sub_binary中执行git登录,我会得到一次提交的预期历史记录。
  • 当我尝试在git pull --depth 1中执行sub_binary时,出现合并错误:自动合并失败;修复冲突,然后提交结果。
  • 我正在使用git 1.8.4
  • 我已阅读VonC's answer to Git Shallow Submodules,但未提及如何更新此类子模块。

编辑:

经过大量的git学习(see my own answer)后,我能够更新子模块。但是仍有一个问题是主要的回购会随着新版本的推出而增长。

对于一个测试,我有一个二进制文件,大小为2 meg,我会浅层克隆以创建一个子模块。 du -h后的初始克隆git submodule update --init --depth 1

 40K    ./.git/hooks
4.0K    ./.git/info
4.0K    ./.git/logs/refs/heads
4.0K    ./.git/logs/refs/remotes/origin
4.0K    ./.git/logs/refs/remotes
8.0K    ./.git/logs/refs
 12K    ./.git/logs
 40K    ./.git/modules/sub_binary/hooks
4.0K    ./.git/modules/sub_binary/info
4.0K    ./.git/modules/sub_binary/logs/refs/heads
4.0K    ./.git/modules/sub_binary/logs/refs/remotes/origin
4.0K    ./.git/modules/sub_binary/logs/refs/remotes
8.0K    ./.git/modules/sub_binary/logs/refs
 12K    ./.git/modules/sub_binary/logs
  0B    ./.git/modules/sub_binary/objects/info
2.0M    ./.git/modules/sub_binary/objects/pack
2.0M    ./.git/modules/sub_binary/objects
4.0K    ./.git/modules/sub_binary/refs/heads
4.0K    ./.git/modules/sub_binary/refs/remotes/origin
4.0K    ./.git/modules/sub_binary/refs/remotes
  0B    ./.git/modules/sub_binary/refs/tags
8.0K    ./.git/modules/sub_binary/refs
2.1M    ./.git/modules/sub_binary
2.1M    ./.git/modules
4.0K    ./.git/objects/70
4.0K    ./.git/objects/de
4.0K    ./.git/objects/info
8.0K    ./.git/objects/pack
 20K    ./.git/objects
4.0K    ./.git/refs/heads
4.0K    ./.git/refs/remotes/origin
4.0K    ./.git/refs/remotes
  0B    ./.git/refs/tags
8.0K    ./.git/refs
2.2M    ./.git
2.0M    ./sub_binary
4.2M    .
经过两三个更新周期后

du -h

 40K    ./.git/hooks
8.0K    ./.git/info
4.0K    ./.git/logs/refs/heads
4.0K    ./.git/logs/refs
8.0K    ./.git/logs
 40K    ./.git/modules/sub_binary/hooks
8.0K    ./.git/modules/sub_binary/info
  0B    ./.git/modules/sub_binary/logs/refs/heads
8.0K    ./.git/modules/sub_binary/logs/refs/remotes/origin
8.0K    ./.git/modules/sub_binary/logs/refs/remotes
8.0K    ./.git/modules/sub_binary/logs/refs
 12K    ./.git/modules/sub_binary/logs
4.0K    ./.git/modules/sub_binary/objects/0a
4.0K    ./.git/modules/sub_binary/objects/1b
2.0M    ./.git/modules/sub_binary/objects/a0
4.0K    ./.git/modules/sub_binary/objects/info
4.0M    ./.git/modules/sub_binary/objects/pack
6.0M    ./.git/modules/sub_binary/objects
  0B    ./.git/modules/sub_binary/refs/heads
8.0K    ./.git/modules/sub_binary/refs/remotes/origin
8.0K    ./.git/modules/sub_binary/refs/remotes
  0B    ./.git/modules/sub_binary/refs/tags
8.0K    ./.git/modules/sub_binary/refs
6.1M    ./.git/modules/sub_binary
6.1M    ./.git/modules
4.0K    ./.git/objects/70
4.0K    ./.git/objects/de
4.0K    ./.git/objects/info
8.0K    ./.git/objects/pack
 20K    ./.git/objects
4.0K    ./.git/refs/heads
  0B    ./.git/refs/tags
4.0K    ./.git/refs
6.2M    ./.git
2.0M    ./sub_binary
8.2M    .

由于我以浅层重置并重置,我认为repo只包含一个文件副本+工作目录,大约4兆。

2 个答案:

答案 0 :(得分:2)

在我的特定用例中,由于二进制数据,我无法合并或拉取。所以解决方案很简单:

cd sub_module
git fetch --depth 1
git reset --hard origin/master
cd ..
git add sub_module
git commit -m 'updated sub_module'

答案 1 :(得分:0)

由于子模块几乎总是处于分离头模式,因此不会起作用:

git fetch --depth 1
git checkout sub_binary/master

编辑:

此帖子here表示git pull应该有效。遥控器的头部和子模块的头部之间是否有线性历史记录?