Git 对象
| Attribute | Commit Object | Tree Object | Blob Object |
|---|---|---|---|
| Stored Content | Top-level tree hash Parent commit hash(es) Author & Committer Commit message | A list of entries, each with: • Mode (permissions) • Type (blob/tree) • SHA-1 Hash • Filename | Raw file content |
| Points To | A Tree object Parent Commit(s) | Blob(s) Other Tree(s) | Nothing |
| Key Purpose | Records a project snapshot and links it to version history | Represents a directory’s content | Stores the content of a file |
Commit 对象
每一次 commit 都创建一个 commit 对象,存放 1.Author & Committer Commit message 2.指向上一次 commit 对象的指针 3.指向根目录的 tree 对象的指针
Tree 对象
存放指针指向根目录下的文件以及子目录
每一个目录都有Tree对象
内容发生了变化的目录 创建新的 tree 对象。
目录及其所有子目录内容都没有任何改变,新提交会直接指向旧的 tree 对象
以根目录为例
$ git ls-tree -l HEAD100644 blob 29a082782f3c4424359998270562e847761001a1 12 README.md040000 tree 7c2a715a31f7957f8273f68481a7983ea4e514a6 - src模式 (mode) | 类型 (type) | 哈希值 (SHA-1 hash) | 大小 (size) | 路径 (path) |
|---|---|---|---|---|
100644 | blob | 29a0827... | 12 | README.md |
040000 | tree | 7c2a715... | - | src |
Blob 对象
Binary Large Object 只存放文件的原始数据,即二进制文件
blob 对象的哈希值 (SHA-1) 是由其内容计算得到
只要两个文件的内容完全相同,无论它们在项目中的哪个位置,叫什么名字,它们都会指向同一个 blob 对象。