You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The blob is now a different blob, which means that although you added only a single line to the end of a 400-line file, Git stored that new content as a completely new object:
You have two nearly identical 22K objects on your disk.
85
-
Wouldn't it be nice if Git could store one of them in full but then the second object only as the delta between it and the first?
84
+
你的磁盘上现在有两个几乎完全相同、大小均为 22K 的对象。
85
+
如果 Git 只完整保存其中一个,再保存另一个对象与之前版本的差异内容,岂不更好?
86
86
87
-
It turns out that it can.
88
-
The initial format in which Git saves objects on disk is called a ``loose'' object format.
89
-
However, occasionally Git packs up several of these objects into a single binary file called a ``packfile'' in order to save space and be more efficient.
90
-
Git does this if you have too many loose objects around, if you run the `git gc`command manually, or if you push to a remote server.
91
-
To see what happens, you can manually ask Git to pack up the objects by calling the `git gc`command:
The other files are your new packfile and an index.
120
-
The packfile is a single file containing the contents of all the objects that were removed from your filesystem.
121
-
The index is a file that contains offsets into that packfile so you can quickly seek to a specific object.
122
-
What is cool is that although the objects on disk before you ran the `gc`were collectively about 22K in size, the new packfile is only 7K.
123
-
You've cut your disk usage by ⅔ by packing your objects.
118
+
剩下的文件是新创建的包文件和一个索引。
119
+
包文件包含了刚才从文件系统中移除的所有对象的内容。
120
+
索引文件包含了包文件的偏移信息,我们通过索引文件就可以快速定位任意一个指定对象。
121
+
有意思的是运行 `gc`命令前磁盘上的对象大小约为 22K,而这个新生成的包文件大小仅有 7K。
122
+
通过打包对象减少了 ⅔ 的磁盘占用空间。
124
123
125
-
How does Git do this?
126
-
When Git packs objects, it looks for files that are named and sized similarly, and stores just the deltas from one version of the file to the next.
127
-
You can look into the packfile and see what Git did to save space.
128
-
The `git verify-pack`plumbing command allows you to see what was packed up:
124
+
Git 是如何做到这点的?
125
+
Git 打包对象时,会查找命名及大小相近的文件,并只保存文件不同版本之间的差异内容。
126
+
你可以查看包文件,观察它是如何节省空间的。
127
+
`git verify-pack`这个底层命令可以让你查看已打包的内容:
129
128
130
129
[source,console]
131
130
----
@@ -156,9 +155,9 @@ chain length = 1: 3 objects
156
155
.git/objects/pack/pack-978e03944f5c581011e6998cd0e9e30000905586.pack: ok
157
156
----
158
157
159
-
Here, the `033b4`blob, which if you remember was the first version of your repo.rb file, is referencing the `b042a` blob, which was the second version of the file.
160
-
The third column in the output is the size of the object in the pack, so you can see that `b042a`takes up 22K of the file, but that `033b4`only takes up 9 bytes.
161
-
What is also interesting is that the second version of the file is the one that is stored intact, whereas the original version is stored as a delta – this is because you're most likely to need faster access to the most recent version of the file.
The really nice thing about this is that it can be repacked at any time.
164
-
Git will occasionally repack your database automatically, always trying to save more space, but you can also manually repack at any time by running `git gc`by hand.
0 commit comments