操作系统原理 2026

blob、tree 与 commit

原片 00:37:00—00:38:31

现在看到了两个 objects:旧版 Hello、新版 Hello, World,确实都在 objects 中。三类对象里,blob 保存 a.txt、cpp 等文件内容,以压缩形式存储;tree 则表示文件系统树,这里有 100644。

图 28:Hello, World 与新旧 commit 对象(00:36:58)。
图 28:Hello, World 与新旧 commit 对象(00:36:58)。

这是 mode,记录文件是否可执行,保存在 tree object 中。后面还有数据结构描述,需要再写程序解码。commit 是文本,包括 commit message,比如 add a.txt、modify a.txt,还有 author、时间戳及 tree,每个 commit 都指向 tree object。

图 29:Hello 与原始 commit 对象(00:37:04)。
图 29:Hello 与原始 commit 对象(00:37:04)。

还有 parent object。比如 tree 是 25086,就能找到对应 25 目录下的 086a 等对象。Git 用文件系统实现 persistent data structure,append-only 就是持续往对象池加入文件,再通过 random read 读取。

输入关键词,搜索全部 30 节课。