我正在寻找如何处理我的源代码(web应用程序)依赖的大型二进制文件的意见。我们目前正在讨论几种替代方案:

Copy the binary files by hand. Pro: Not sure. Contra: I am strongly against this, as it increases the likelihood of errors when setting up a new site/migrating the old one. Builds up another hurdle to take. Manage them all with Git. Pro: Removes the possibility to 'forget' to copy a important file Contra: Bloats the repository and decreases flexibility to manage the code-base and checkouts, clones, etc. will take quite a while. Separate repositories. Pro: Checking out/cloning the source code is fast as ever, and the images are properly archived in their own repository. Contra: Removes the simpleness of having the one and only Git repository on the project. It surely introduces some other things I haven't thought about.

你对此有什么经验/想法?

还有:有人有在一个项目中使用多个Git存储库并管理它们的经验吗?

这些文件是用于生成包含这些文件的pdf文件的程序的图像。这些文件不会经常更改(例如几年),但它们与程序非常相关。没有这些文件,程序将无法工作。


当前回答

我最近发现了git-annex,我觉得很棒。它是为有效地管理大文件而设计的。我用它来收集我的照片/音乐(等)。git-annex的开发非常活跃。文件的内容可以从Git存储库中删除,Git只跟踪树的层次结构(通过符号链接)。然而,要获得文件的内容,在拉/推之后需要第二步,例如:

$ git annex add mybigfile
$ git commit -m'add mybigfile'
$ git push myremote
$ git annex copy --to myremote mybigfile ## This command copies the actual content to myremote
$ git annex drop mybigfile ## Remove content from local repo
...
$ git annex get mybigfile ## Retrieve the content
## or to specify the remote from which to get:
$ git annex copy --from myremote mybigfile

有很多可用的命令,网站上有很好的文档。Debian上有一个软件包。

其他回答

SVN似乎比Git更有效地处理二进制增量。

我必须决定文档的版本控制系统(JPEG文件、PDF文件和.odt文件)。我刚刚测试了添加一个JPEG文件并将其旋转90度4次(以检查二进制增量的有效性)。Git的存储库增长了400%。SVN的存储库仅增长了11%。

因此,看起来SVN使用二进制文件更有效率。

所以我选择Git作为源代码,SVN作为文档之类的二进制文件。

在我看来,如果您可能经常修改这些大文件,或者您打算进行大量的git克隆或git签出,那么您应该认真考虑使用另一个git存储库(或者可能是访问这些文件的另一种方法)。

但是如果您像我们一样工作,并且您的二进制文件不经常修改,那么第一次克隆/签出将会很长,但是在那之后它应该和您想要的一样快(考虑到您的用户一直使用他们拥有的第一个克隆存储库)。

git克隆——过滤从git 2.19 +浅克隆

这个新选项可能最终会成为二进制文件问题的最终解决方案,如果Git和GitHub开发并使其足够友好(他们可以说仍然没有实现子模块例如)。

它实际上只允许为服务器获取您想要的文件和目录,并与远程协议扩展一起引入。

有了这个,我们可以先做一个浅克隆,然后自动使用构建系统为每种类型的构建获取哪些blobs。

甚至已经有一个——filter=blob:limit<size>,它允许限制读取的最大blob大小。

我提供了一个关于该特性的最小详细示例:如何克隆Git存储库的子目录?

看看camlistore。它不是真正基于git的,但我发现它更适合您必须做的事情。

看看git bup,这是一个git扩展,可以聪明地在git存储库中存储大型二进制文件。

您希望将它作为子模块使用,但不必担心存储库变得难以处理。他们的一个示例用例是在Git中存储VM映像。

实际上我还没有看到更好的压缩率,但我的存储库中并没有真正大的二进制文件。

你的里程可能会有所不同。