应用状态演练
这个演练跟踪一个小型应用数据目录:一个 SQLite 数据库、一个 JSON 配置文件 和一个附件。运行下面的本地命令前,可以先在 浏览器 Playground 中练习同一套概念。
创建应用状态
Section titled “创建应用状态”mkdir graft-walkthroughcd graft-walkthroughgraft init
graft sql --db data.sqlite "CREATE TABLE docs(id TEXT PRIMARY KEY, title TEXT, attachment TEXT);"graft sql --db data.sqlite "INSERT INTO docs VALUES ('doc-1', 'Proposal', 'attachments/proposal.txt');"
mkdir -p attachmentsprintf 'proposal draft\n' > attachments/proposal.txtprintf '{ "theme": "light" }\n' > settings.json提交:
graft status --jsongraft add --allgraft commit -m "seed app state"这个 commit 同时记录 data.sqlite、settings.json 和
attachments/proposal.txt。
graft switch -c rewrite-titlegraft sql --db data.sqlite "UPDATE docs SET title = 'Updated Proposal' WHERE id = 'doc-1';"printf 'proposal draft v2\n' > attachments/proposal.txtgraft diff --rows HEAD data.sqlitegraft add --allgraft commit -m "rewrite proposal"切回 main:
graft switch maingraft sql --db data.sqlite "SELECT id, title, attachment FROM docs;"cat attachments/proposal.txtgraft merge rewrite-titlegraft status有冲突时:
graft conflicts --jsongraft resolve --theirs data.sqlitegraft merge --continue -m "merge rewrite"本地远端 smoke test:
mkdir -p /tmp/graft-remotegraft remote add origin fs:///tmp/graft-remotegraft push origin main克隆:
mkdir ../graft-clonecd ../graft-clonegraft clone fs:///tmp/graft-remote maingraft sql --db data.sqlite "SELECT id, title FROM docs;"