gpt4 book ai didi

git - git commit占用了多少磁盘空间

转载 作者:太空狗 更新时间:2023-10-29 14:27:34 27 4
gpt4 key购买 nike

根据这个页面 http://www.eecs.harvard.edu/~cduan/technical/git/git-1.shtml

一个提交对象包含三个东西:

  • A set of files, reflecting the state of a project at a given point in time.
  • References to parent commit objects.
  • An SHA1 name, a 40-character string that uniquely identifies the commit object. The name is composed of a hash of relevant aspects of the commit, so identical commits will always have the same name.

我的问题是关于第一点: 如果我当前的项目大小是 10MB,那么添加一个新提交将再占用 10MB?因为根据第一点,每个提交都包含一组反射(reflect)项目状态的文件。

最佳答案

我不确定其他答案是否真的完全解决了您的问题。

Git 分别存储提交和实际文件内容。提交不包含文件——它包含对提交包含的文件的散列 的引用。文件与提交分开存储,如果两个提交具有相同版本的文件,则这两个提交将引用相同的哈希,但文件本身不会重复。如果一个文件在两次提交之间发生变化,该文件将被存储两次,文件的每个版本都有自己的哈希值,并且提交将引用不同的哈希值。

假设您从一个提交开始,其中包含两个文件 a.txt 和 b.txt,每个文件都散列为不同的值:

Commit 1:
Filename | Hash
---------------------
a.txt | abcdef111111
b.txt | ghijkl222222

请注意,提交不包含文件内容。 Git 已将文件内容和哈希值存储在别处。

File store:
Hash | File contents
---------------------------------
abcdef111111 | hello world
ghijkl222222 | int main()

假设您更新了 a.txt,并进行了新的提交。首先,Git 将文件的新版本存储在其文件内容存储中:

File store:
Hash | File contents
---------------------------------
abcdef111111 | hello world
ghijkl222222 | int main()
zyxwvu999999 | goodbye world <-- new entry

并且新的提交指向包含 a.txt 内容的散列:

Commit 2:
Filename | Hash
---------------------
a.txt | zyxwvu999999
b.txt | ghijkl222222

因为b.txt没有变化,所以没必要再存储。第二次提交仅引用与第一次提交相同的哈希值。

关于git - git commit占用了多少磁盘空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6523998/

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