Diff, merge and undo
See what a branch changed, merge it into another, settle conflicts, and undo commits.
Review what a branch changed, bring its work into another branch, and take back a change you don't want.
echo "retries = 3" | skywake write app/config.toml
skywake fork app agent-1
echo "export const ttl = 3600;" | skywake write app@agent-1/src/session.ts -m "Add sessions"
echo "retries = 5" | skywake write app@agent-1/config.toml
skywake diff app@agent-1
skywake merge app@agent-1 --dry-run
skywake merge app@agent-1 -m "Sessions from agent-1"
skywake log app --limit 3Diff
work.diff("main") (CLI: skywake diff app@agent-1 [main]) lists the paths that differ between the branch and another branch or commit, each with its change: added, removed or modified. The CLI marks them +, - and ~. A folder that is new on one side shows up once, not file by file. Folders that didn't change are skipped without being read, so a diff costs as much as what changed, whatever the size of the tree.
The comparison is with the other branch as it is now, so changes made on main since the fork show up too.
Merge
work.mergeInto("main") (CLI: skywake merge app@agent-1, --into for another branch) brings the branch's changes into another. It is a three-way merge against the newest commit both branches share.
- When both sides changed a text file in different places, the changes are merged line by line.
- A file's mode is merged on its own, apart from its content.
- When changes overlap, nothing is saved and the merge fails with
MergeConflict. Itsconflictslists the paths. The CLI printsconflict: PATHfor each and exits non-zero.
| Option | CLI | Meaning |
|---|---|---|
message | -m | The merge commit's message. |
dryRun | --dry-run | Only report the conflicts the merge would have now. Saves nothing. |
prefer | — | Settle every conflict by keeping into's side (ours) or the merged branch's (theirs). |
The result is { commit, conflicts }. Merges into one branch take turns, like any other write.
Settle conflicts yourself
To combine both sides instead of picking one, merge the other way first, then write the result on the fork:
- Try the merge. On
MergeConflict, read each conflicting path on both branches and decide what it should hold. - Merge
maininto the fork withprefer: "ours". The fork now includesmain, keeping its own side of each conflict. - Write the settled files on the fork, and merge it into
mainagain. This time nothing overlaps.
import { MergeConflict, Skywake } from "skywake";
const sky = new Skywake();
const app = sky.disk("app");
await app.write("TODO.md", "- ship login\n");
const work = await app.fork("agent-1");
await work.write("TODO.md", "- ship login\n- add sessions\n");
await app.write("TODO.md", "- ship login\n- fix signup\n");
const combine = (ours: string, theirs: string) =>
[...new Set([...ours.split("\n"), ...theirs.split("\n")])].filter(Boolean).join("\n") + "\n";
try {
await work.mergeInto("main");
} catch (error) {
if (!(error instanceof MergeConflict)) throw error;
const settled: Record<string, string> = {};
for (const path of error.conflicts) {
settled[path] = combine(await app.read(path), await work.read(path));
}
await app.mergeInto(work.branch, { prefer: "ours" });
await work.write(settled, { message: "Settle conflicts with main" });
await work.mergeInto("main");
}
console.log(await app.read("TODO.md"));combine is your own code, such as an agent that reads both versions and writes one.
Per-path choices in a single merge request (resolve, with take, text or delete for each path) exist only on the v1 API, POST /v1/namespaces/{namespace}/merges. /v1 goes away one release after v2.
Undo
import { Skywake } from "skywake";
const app = new Skywake().disk("app");
const good = await app.write("config.toml", "retries = 3\n", { message: "Set retries" });
const bad = await app.write("config.toml", "retries = 0\n", { message: "Turn retries off" });
console.log("then:", await app.read("config.toml", { at: good.commit }));
await app.revert(bad.commit);
console.log("after revert:", await app.read("config.toml"));
await app.write("notes.md", "draft\n");
await app.restore(good.commit);
console.log("after restore:", await app.exists("notes.md"));
for await (const commit of app.log({ limit: 5 })) {
console.log(commit.id.slice(0, 12), commit.message);
}app.revert(commit)undoes one commit by adding a new commit that puts back what it changed. For a merge commit, it goes back to the first parent. If later commits changed the same paths again, nothing is saved and it fails withMergeConflict.app.restore(commitOrTime)makes the branch look like it did then, as one new commit on top. The commit can come from any branch of the disk. In TypeScript aDatepicks the newest commit at or before that time.read,list,grep,findanddownloadtakeatto look at the past without changing anything.
Both return { commit, changed }. changed is false when there was nothing to undo. Both need a write key. A protected branch refuses both, because it changes only through a merge. There is no CLI command for revert or restore yet; use an SDK or POST /v2/disks/{disk}/revert and /restore.
History
app.log({ path, limit }) lists commits newest first: each has an id, a message, when it was created, and for a merge, the commit it merged. Pass path to see only the commits that changed one file. In the CLI it is skywake log app@agent-1 --path src/app.py --limit 10.