gpt4 book ai didi

git - Git 存储文本文件和二进制文件的方式有区别吗

转载 作者:行者123 更新时间:2023-12-02 17:02:04 31 4
gpt4 key购买 nike

每个人似乎都同意的一件事是 Git 不适用于大型二进制 blob。请记住,二进制 blob 不同于大型文本文件;您可以毫无问题地在大型文本文件上使用 Git,但 Git 无法对不可渗透的二进制文件做很多事情,除非将其视为一个大的实心黑框并按原样提交。

根据 https://opensource.com/life/16/8/how-manage-binary-blobs-git-part-7 :

One thing everyone seems to agree on is Git is not great for bigbinary blobs. Keep in mind that a binary blob is different from alarge text file; you can use Git on large text files without aproblem, but Git can't do much with an impervious binary file excepttreat it as one big solid black box and commit it as-is.

Say you have a complex 3D model for the exciting new first personpuzzle game you're making, and you save it in a binary format,resulting in a 1 gigabyte file. You git commit it once, adding agigabyte to your repository's history. Later, you give the model adifferent hair style and commit your update; Git can't tell the hairapart from the head or the rest of the model, so you've just committedanother gigabyte. Then you change the model's eye color and committhat small change: another gigabyte. That is three gigabytes for onemodel with a few minor changes made on a whim. Scale that across allthe assets in a game, and you have a serious problem.

据我了解,文本文件和二进制文件之间没有区别,Git 完整地存储每次提交的所有文件(创建校验和 blob),未更改的文件只是指向一个已经存在的 blob。如何存储和压缩所有这些 blob 是另一个问题,我不知道详细信息,但我假设如果报价中的各种 1GB 文件或多或少相同,一个好的压缩算法会解决这个问题如果它们是重复的,并且可能能够将它们全部存储在甚至不到 1GB 的空间中。这个推理应该适用于二进制文件和文本文件。

与此相反,引用继续说

Contrast that to a text file like the .obj format. One commit storeseverything, just as with the other model, but an .obj file is a seriesof lines of plain text describing the vertices of a model. If youmodify the model and save it back out to .obj, Git can read the twofiles line by line, create a diff of the changes, and process a fairlysmall commit. The more refined the model becomes, the smaller thecommits get, and it's a standard Git use case. It is a big file, butit uses a kind of overlay or sparse storage method to build a completepicture of the current state of your data.

我的理解对吗?引用不正确吗?

最佳答案

Git 会完整地存储文件,因此如果您有 2 个二进制文件且只有很小的更改,它将占用两倍的空间。观察。

% git init                
Initialized empty Git repository in /tmp/x/.git/
{master #}% [/tmp/x]
{master #}% du -sh .git
100K .git
{master #}% dd if=/dev/urandom of=./test count=1 bs=10M
1+0 records in
1+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.102277 s, 103 MB/s
{master #%}% ls -sh test
10M test
{master #%}% git add test
git co%
{master #}% git commit -m "Adds test"
[master (root-commit) 0c12c32] Adds test
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test
{master}% du -sh .git
11M .git

我创建了一个 10MB 的文件并添加并提交了它。存储库现在大小为 10MB。

如果我做了一个小改动然后再做一次,

{master}% e test # This is an invocation of my editor to change a few bytes.
nil
{master}% git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: test

no changes added to commit (use "git add" and/or "git commit -a")
{master *}% git add test
{master +}% git commit -m "Updates test a little"
[master 99ed99a] Updates test a little
1 file changed, 0 insertions(+), 0 deletions(-)
{master}% du -sh .git
21M .git

这将需要 20MB。 10MB 文件的两倍。

然而,这是存储库的“loose object”格式,其中每个 blob 都是磁盘上的一个单独文件。

您可以将所有这些打包到一个 git 包文件中(这在您推送等时完成),然后看看会发生什么。

{master}% git gc
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), done.
Total 6 (delta 1), reused 0 (delta 0)
{master}% du -sh .git
11M .git

现在,它只在 packfile 中存储 blob 和 diff 一次.这不同于每个只存储差异的提交。就是将对象本身打包到一个文件中。

关于git - Git 存储文本文件和二进制文件的方式有区别吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53647783/

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