简体   繁体   English

git 提交和 git 提交 object 之间的区别以及它们的存储方式

[英]difference between git commit and git commit object and how each is stored

The amazing git pro book, mentions the following:令人惊叹的git 专业书,提到以下内容:

commit object that contains a pointer to the snapshot of the content you staged.提交 object ,其中包含指向您暂存的内容快照的指针。 This object also contains the author's name and email address, the message that you typed, and pointers to the commit or commits that directly came before this commit (its parent or parents)...此 object 还包含作者姓名和 email 地址、您键入的消息以及指向直接在此提交之前的提交(其父级或父级)的指针......

and further,并进一步,

Your Git repository now contains five objects: three blobs (each representing the contents of one of the three files), one tree that lists the contents of the directory and specifies which file names are stored as which blobs, and one commit with the pointer to that root tree and all the commit metadata .您的 Git 存储库现在包含五个对象:三个 blob(每个代表三个文件之一的内容),一棵列出目录内容并指定将哪些文件名存储为哪些 blob 的树,以及一个带有指向的提交该根树和所有提交元数据

The first bold texts almost differentiate between commit and commit object without much clarifying it.第一个粗体文本几乎将提交提交 object 区分开来,没有太多澄清。 The second bold texts tell us that a commit is stored , but does that mean a commit object is only temporarily created?第二个粗体文本告诉我们提交已存储,但这是否意味着提交 object 只是临时创建的? Git gurus, please clarify this to me. Git 大师,请向我澄清这一点。

There's four kinds of objects in the repo's object db: blobs, trees, commits and (the annotated) tags. repo 的 object db 中有四种对象:blob、trees、commits 和(带注释的)标签。 "A commit" is a commit object, stored in a repo's object db. “提交”是提交 object,存储在存储库的 object 数据库中。 That's it.而已。 You can actually build the zlib test/demo sources and zpipe -d a commit object's file to see exactly the text git cat-file -p will show you.您实际上可以构建 zlib 测试/演示源和zpipe -d提交对象的文件以准确查看git cat-file -p将显示给您的文本。 It really is that simple.真的就是这么简单。

Seriously: fetch the zlib source and build zpipe.说真的:获取 zlib 源并构建 zpipe。 Then do commands in a toy repo you build with --template= to shut off all the samples, or get really bare-bones and do this:然后在您使用--template=构建的玩具仓库中执行命令以关闭所有示例,或者获得真正的准系统并执行以下操作:

mkdir -p mytest/.git/{objects,refs}
echo ref: refs/heads/main >mytest/.git/HEAD
cd mytest
git status

to see that puts you in a fully-operational git repo.看到这会让您进入一个完全可操作的 git 存储库。 This is not a trick.这不是诡计。 Now make a file and git add it and say find .现在创建一个文件并 git 添加它并说find Then make a commit and say find again.然后提交并再次说find cat or zpipe -d the files that showed up in the repo. catzpipe -d显示在 repo 中的文件。

See jthill's answer , but to some extent I'll note that this is "just" a terminology issue.请参阅jthill 的回答,但在某种程度上我会注意到这“只是”一个术语问题。 I put "just" in quote because terminology and semantics are crucial to actual understanding , and the phrase mere semantics kind of puts me on edge: semantics aren't mere at all.我把“只是”放在引号中,因为术语和语义对于实际理解至关重要,而纯粹的语义这句话让我感到紧张:语义根本不只是 They are essential, Without semantics.它们是必不可少的,没有语义。 nothing we say has any meaning.我们所说的没有任何意义。

A useful distinction is to say that a Git commit—the noun—refers to:一个有用的区别是说 Git 提交(名词)指的是:

  • the commit object, plus提交 object,加上
  • its supporting tree object and any sub-trees and blob objects它的支持树 object 和任何子树和 blob 对象

and therefore it's the entire saved snapshot plus the metadata.因此它是整个保存的快照加上元数据。 1 Meanwhile, a commit object —where we use the word commit as an adjective modifying the noun object —is merely the commit object itself, consisting entirely of commit metadata, since the saved snapshot is found indirectly through the tree line. 1同时,提交object — 我们使用单词commit作为形容词来修饰名词object — 仅仅是提交 object 本身,完全由提交树元数据组成,因为保存的快照是通过提交tree行间接找到的。

As matt points out in a footnote , we also have the verb form, to commit , which means to make one of these commit objects that uses a tree object that uses subtrees and/or blobs.正如马特在脚注中指出的那样,我们还有动词形式to commit ,这意味着创建这些提交对象之一,该对象使用使用子树和/或 blob 的树 object。

In the end, then, the semantics are:最后,语义是:

  • to commit: commit as a verb, meaning to make a commit; to commit:commit作为动词,意思是提交;
  • a commit: commit as a noun, meaning the whole ball of wax; a commit:commit 作为名词,意思是整个蜡球; and
  • a commit object: commit as an adjective, modifying object, meaning the internal Git object that stores only the metadata part of the whole-ball-of-wax. a commit object: commit as an adjective, modifying object, meaning the internal Git object that stores only the metadata part of the whole-ball-of-wax.

Humans being human, and natural language being what it is, you'll see the terms being used inappropriately, with the expectation that the reading/listening human will receive instead what the writing/speaking human intended to say.人类是人类,自然语言就是这样,您会看到这些术语的使用不当,期望阅读/听力的人会收到写作/口语的人想要说的内容。


1 Note that this means that I disagree with jthill's definition, which defines commit and commit object as the same thing. 1请注意,这意味着我不同意 jthill 的定义,它将commitcommit object定义为同一件事。 That's OK.没关系。 Different people can have different definitions.不同的人可以有不同的定义。 The aim of the last claim before this footnote is that we should try to understand what someone else meant , even if that requires adapting to their terminology for a while.这个脚注之前的最后一个主张的目的是我们应该尝试理解其他人的意思,即使这需要一段时间适应他们的术语。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM