git - git 是否将差异信息存储在提交对象中?

标签 git diff

根据 this :

It is important to note that this is very different from most SCM systems that you may be familiar with. Subversion, CVS, Perforce, Mercurial and the like all use Delta Storage systems - they store the differences between one commit and the next. Git does not do this - it stores a snapshot of what all the files in your project look like in this tree structure each time you commit. This is a very important concept to understand when using Git.

然而,当我运行 git show $SHA1ofCommitObject 时......

commit 4405aa474fff8247607d0bf599e054173da84113
Author: Joe Smoe <joe.smoe@example.com>
Date:   Tue May 1 08:48:21 2012 -0500

    First commit

diff --git a/index.html b/index.html
new file mode 100644
index 0000000..de8b69b
--- /dev/null
+++ b/index.html
@@ -0,0 +1 @@
+<h1>Hello World!</h1>
diff --git a/interests/chess.html b/interests/chess.html
new file mode 100644
index 0000000..e5be7dd
--- /dev/null
+++ b/interests/chess.html
@@ -0,0 +1 @@
+Did you see on Slashdot that King's Gambit accepted is solved! <a href="http://game

... 它输出提交与之前提交的差异。我知道 git 不会在 blob 对象中存储差异,但它会在提交对象中存储差异吗?还是 git show 动态计算差异?

最佳答案

这句话的意思是,大多数其他版本控制系统需要一个过去的引用点才能重新创建当前提交。

例如,在过去的某个时候,基于差异的 VCS(版本控制系统)会存储完整的快照:

x = snapshot
+ = diff
History:
x-----+-----+-----+-----(+) Where we are now

因此,在这种情况下,要重新创建(现在)的状态,它必须检查 (x),然后为每个 (+) 应用差异,直到到达现在。请注意,永久存储增量是非常低效的,因此基于增量的 VCS 每隔一段时间就会存储一个完整的快照。 Here's how its done for subversion .

现在,git 不一样了。 Git 存储对完整 blob 的引用,这意味着使用 git,仅一次提交就足以在那个时间点重新创建代码库。 Git 不需要从过去的修订中查找信息来创建快照。

那么如果是这样的话,那么 git 使用的增量压缩从何而来?

好吧,它只不过是一个压缩概念——如果只有很小的变化,将相同的信息存储两次是没有意义的。因此,表示已更改的内容,但存储对它的引用,以便它所属的提交(实际上是一个引用树)仍然可以重新创建而无需查看过去的提交。不过,问题是 Git 不会在每次提交后立即执行此操作,而是在垃圾收集运行时执行此操作。因此,如果 git 没有运行其垃圾回收,您可以在索引中看到内容非常相似的对象。

但是,当 Git 运行其垃圾收集时(或者当您手动调用 git gc 时),重复项将被清理并创建一个只读包文件。您不必担心手动运行垃圾收集 - git 包含启发式方法,告诉它何时这样做。

关于git - git 是否将差异信息存储在提交对象中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10398744/

相关文章:

git - 如何在 git 中将本地更改与远程存储库上的更改集成?

Git 分支模型实现

git - 使用 Github API 在给定日期*和*他们的分支获取所有提交的有效方法

git - 文件在提交之间更改但将文件列表限制为较旧的提交

r - R中两个向量之间的差异

windows - Jenkins Windows 从站 : Authentication failed if running as service

git - 我可以使用 Libre Office 的哪种输出格式来跟踪文件的历史记录?

vim - 有没有办法在 vim 中区分两个寄存器?

r - 比较两个数据帧中的值并返回差异

linux - diff -y 奇怪的输出