不压缩远程对象的情况下进行git pull

41

我有一个装满zip文件的仓库,重新压缩这些文件会浪费时间。

我已经尝试在本地副本和远程副本上设置core.compression = 0,但没有成功。

git config core.compression 0
git config core.loosecompression 0

git pull 仍然是有效的

remote: Counting objects: 23, done.
remote: Compressing objects: ...

2
你有测量性能差异吗?我不会担心压缩已经压缩过的数据所花费的时间;网络很可能比你的CPU慢得多。 - Greg Hewgill
3个回答

62

我遇到的时间问题是由增量压缩引起的。

对于我来说,解决方案是:

echo '*.zip -delta' > .gitattributes
git gc

我将引用这篇来自关于图像、音频文件和其他“非代码”数据存在严重性能问题的回复

Git does spend a fair bit of time in zlib for some workloads, but it should not create problems on the order of minutes.

For pushing and pulling, you're probably seeing delta compression, which can be slow for large files

 core.compression 0   # Didn't seem to work.

That should disable zlib compression of loose objects and objects within packfiles. It can save a little time for objects which won't compress, but you will lose the size benefits for any text files.

But it won't turn off delta compression, which is what the "compressing..." phase during push and pull is doing. And which is much more likely the cause of slowness.

 pack.window 0

It sets the number of other objects git will consider when doing delta compression. Setting it low should improve your push/pull times. But you will lose the substantial benefit of delta-compression of your non-image files (and git's meta objects). So the "-delta" option above for specific files is a much better solution.

 echo '*.jpg -delta' >> .gitattributes

Also, consider repacking your repository, which will generate a packfile that will be re-used during push and pull.

请注意,设置必须在您正在获取/拉取的存储库上进行,而不是您正在获取/拉取到的存储库。

16
建议使用 ">>",因为它会覆盖你可能已经在 .gitattributes 文件中有的任何其他内容:echo '*.zip -delta' >> .gitattributes - scottgwald

8

compressing object一般指执行pack操作,这包括比较文件树等等。这里的"compressing"并不是指core.compression中的"压缩"。


4
你不需要这样做。Git会对文件进行打包,这是一种好的、值得期望的行为。 - user229044
@Doud 我怎么在不打包的情况下搬家? - J-16 SDiZ
1
当我通过http提供git文件夹时,git fetch/pull不会打包任何东西。也许你应该尝试通过http提供你的房子。 - hdorio
1
@Doud,确实,旧的(非智能)http不会压缩内容。但是它(几乎总是)使用更多的带宽 --- 它(几乎总是)发送你不需要的旧提交。 - J-16 SDiZ
3
注意,“压缩对象”这一行是对“git pack-objects”的调用,与“比较树和其他内容”无关。同时,“core.compression”和“pack.compression”会影响打包工作。 - hdorio
3
那么如何在 git clone 时禁用整个 git 存储库的打包?我的带宽没有问题。 - Reishin

2
如果您的远程服务器内存非常有限,这将非常有用。SSH到远程服务器,进入存储库,然后运行以下命令:
git config --add core.bigFileThreshold 1

这将关闭增量压缩。如果你想撤销它:
git config --unset core.bigFileThreshold

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接