1.3. 审视 commit 细节
接下来我们来看看 commit 的细节。
什么是 commit?
之前我们已经知道了 HEAD, 分支头 都是Commit。
我们用 git cat-file
这个命令来分析一下最近的一个 Commit 也就是 HEAD.
我们先不管这个命令怎么来的,直接git cat-file commit HEAD
,就可以看到这个结果:
➜ plumbing-demo git:(main) git cat-file commit HEAD
tree 69d1223f517e74c307a6e34489c87e4c53156197
parent c2645af2b5ab003896c10c1e77203b7d91a036ff
author hustnzj hustnzj@example.com 1663660827 +0800
committer hustnzj hustnzj@example.com 1663661674 +0800
update .gitignore
这就是说 commit
包括了一个 tree
, 一个 parent
, 一个 author
一个 committer
还有 commit message
.
parent
是当前 commit
的父 commit
,author
, committer
, commit message
也应该不难理解。
而tree
之前并没有出现过,它代表的是一个快照,也就是我们通常说的文件夹及其文件在某个点的状态,而没有具体的时间和作者信息。
Git 通过将每一个 tree
和 一个 commit
进行绑定,从而将 tree
绑定在其 commit
历史中。并且对这个 commit
对象指定一个父commit
,也就是另外一个 commit
, 然后通过这个父commit
的父commit
,就可以纵览整个 commit
历史。
注意:每一个 commit
只能够绑定一个且唯一一个 tree
。从上面的输出中,我们可以推测它的ID也是使用了SHA-1
校验和。所有Git内部对象的 ID 都是这样。