CLI 快速开始
CLI 是试用 Graft 的最短路径。graft sql 打开普通物理 SQLite worktree 文件;
repository command 直接调用 Graft control-plane service,不经过 SQLite extension
或 repository PRAGMA。
-
创建示例应用目录。
Terminal window mkdir app-state-democd app-state-demo -
初始化 Graft。
Terminal window graft init这会创建
.graft/,但不会创建默认数据库。 -
写入 SQLite。
Terminal window graft sql --db data.sqlite "CREATE TABLE notes(id INTEGER PRIMARY KEY, body TEXT);"graft sql --db data.sqlite "INSERT INTO notes(body) VALUES ('first note');" -
查看状态。
Terminal window graft statusdata.sqlite仍是普通 SQLite 文件。repository command 需要检查或 stage 该 path 时,Graft 才读取它。 -
提交第一个应用状态版本。
Terminal window graft add --allgraft commit -m "seed notes" -
修改数据库并添加文件。
Terminal window graft sql --db data.sqlite "INSERT INTO notes(body) VALUES ('second note');"mkdir -p attachmentsprintf 'draft\n' > attachments/readme.txt -
查看路径分类。
Terminal window graft status --jsonJSON 里的 path entry 会包含
kind和storage。 -
提交并查看行级 diff。
Terminal window graft add --allgraft commit -m "add second note and attachment"graft diff --rows HEAD~1 HEAD data.sqlite -
从最新 commit 恢复数据库。
Terminal window graft sql --db data.sqlite "DELETE FROM notes;"graft restore --source HEAD -- data.sqlitegraft status
从 stdin 执行 SQL
Section titled “从 stdin 执行 SQL”cat <<'SQL' | graft sql --db data.sqliteCREATE TABLE IF NOT EXISTS notes(id INTEGER PRIMARY KEY, body TEXT);INSERT INTO notes(body) VALUES ('hello from stdin');SELECT * FROM notes;SQL分支里的应用状态
Section titled “分支里的应用状态”branch 和 merge 命令会从当前目录发现仓库并操作整个 repository:
graft switch maingraft --db data.sqlite merge feature/searchgraft merge --continue -m "merge feature/search"switch 会直接 materialize 被跟踪的 worktree paths,不需要数据库选择器。需要
row-aware analysis 时,用 --db 让 merge 打开对应 SQLite 数据库;完成 repository
merge 时不再需要它。
下一步: