比较行与文件
Graft 有两层 diff:
- repository diff:比较 app-state tree 里的路径
- row diff:把 modified SQLite snapshot 展开成 table/row/schema changes
直接比较两个 SQLite 文件
Section titled “直接比较两个 SQLite 文件”当数据库只是两个普通文件,而不是 Graft repository 的两个 side 时,使用
--no-index:
graft diff --no-index old.sqlite new.sqlitegraft diff --no-index --rows old.sqlite new.sqlitegraft diff --no-index --rows --json old.sqlite new.sqlite命令只接受两个普通 SQLite database file,不需要也不会发现 Graft repository。
默认输出说明两个物理 SQLite snapshot 是否不同;--rows 会把 changed pair 展开为
schema、table、row 和 opaque changes。两侧都通过 SQLite online backup 取得一致
snapshot,并包含已提交的 WAL frames。--staged、--root、--kind、--content
等 repository selector 不能与 --no-index 一起使用。
比较 Worktree 和 Staged
Section titled “比较 Worktree 和 Staged”graft diffgraft diff --jsongraft diff --stagedgraft diff --json --staged按 kind 过滤:
graft diff --kind sqlite_databasegraft diff --kind text_filegraft diff --kind binary_file比较 Commit
Section titled “比较 Commit”graft diff HEAD~1 HEADgraft diff HEAD~1 HEAD data.sqlitegraft diff --json HEAD~1 HEADpath-level 输出会说明每个路径的 change、kind 和 storage。
SQLite Row Diff
Section titled “SQLite Row Diff”graft diff --rows HEAD~1 HEAD data.sqlitegraft diff --json --rows HEAD~1 HEAD data.sqliteJSON 中常见 logical_status:
| Status | 含义 |
|---|---|
logical_changes | 找到支持的 row/schema changes。 |
unsupported_logical_surface | SQLite 变化触及无法完整解释的表面。 |
file_changed_no_supported_logical_changes | 文件变了,但支持的逻辑行和 schema 没有净变化。 |
row_diff_unavailable | 此文件无法产生 row diff。 |
真实 CLI 输出
Section titled “真实 CLI 输出”下面是一次真实 graft 运行捕获到的输出。你本机的 hash 和时间会不同。
$ graft diff --rows HEAD~1 HEAD app.sqliteRow Diff 55c99f73d879..d5cb39df069bmodified: app.sqlite Diff LSN 2 -> 4 ============================
Table 'tasks': +1 inserts ~1 updates ~ rowid 2: old: [Null, Text("record cli output"), Text("open")] new: [Null, Text("record cli output"), Text("blocked")] + rowid 4: [Null, Text("publish docs"), Text("open")]比较两个分支时,输出展示的是从 main 变成 feature/progress 需要的 row changes:
$ graft diff --rows main feature/progress app.sqliteRow Diff d5cb39df069b..89abefbeb063modified: app.sqlite Diff LSN 4 -> 4 ============================
Table 'tasks': +1 inserts -1 deletes ~2 updates - rowid 4: [Null, Text("publish docs"), Text("open")] ~ rowid 2: old: [Null, Text("record cli output"), Text("blocked")] new: [Null, Text("record cli output"), Text("open")] + rowid 3: [Null, Text("add screenshots"), Text("open")] ~ rowid 1: old: [Null, Text("write quickstart"), Text("open")] new: [Null, Text("write quickstart"), Text("done")]普通应用 UI 应使用 repository commits 和 revspecs。LSN 与底层 page history 见 SQLite 如何变成快照。