uir diff lists the symbols a module root added, removed, and changed between two Git commits, or between two revisions an external producer published with uir import (see external roots), and with --stat how many lines each symbol gained and lost. It reads the two commits' snapshots from the index and, for line counts only, the two commits' blobs from a registered checkout. With --auto-index, missing clean snapshots are generated from temporary Git worktrees without changing the registered checkout or its head snapshot. The design is in symbol-index-storage.md; the implementation is the symboldiff package.
uir diff <range> [--root <module>] [--location <checkout>] [--visibility exported|internal|all] [--change-type <pattern>...] [--stat] [--auto-index] [--include-tests] [--snapshot-from <uuid>] [--snapshot-to <uuid>]
uir diff <from> <to> [same flags]
uir diff <rev> [--root <module>] [--location <checkout>] [--visibility exported|internal|all] [--change-type <pattern>...] [--untracked] [--stat]
git diff HEAD~3 | uir diff [-] [--visibility exported|internal|all] [--change-type <pattern>...] [--stat]Revisions are read as git diff reads them, by letting git resolve them rather than re-implementing its syntax:
| Revisions | Compares |
|---|---|
A..B, A.., ..B |
A to B; an empty side is HEAD. |
A B |
A to B. |
A...B |
The merge base of A and B to B. More than one merge base fails. |
A^!, A^-, A^-n |
A's first (or nth) parent to A. |
A |
A to the worktree of the checkout it resolved in, through the patch path (see comparing with the worktree). |
pr:N |
The head of pull request N, fetched from origin; usable on either side of .. and ... and as either of two revisions. |
Two revisions are each resolved as before: a full 40- or 64-character commit hash is used as is; anything else is resolved with git rev-parse --verify <rev>^{commit} in the root's registered checkouts, --location (or the current checkout) first. A single spec is expanded with git rev-parse --revs-only in the first checkout that knows it: one positive and one negative commit are a range, two positives and one negative (A...B) are the merge base to B, and a lone positive is a single revision only when the spec itself names one commit. Anything else (A^@, ^A, an A^! of a merge commit) fails, naming the commits the spec expanded to. In Go, symboldiff.ResolveRevisions returns the resolved pair, or the single commit and its checkout.
| Flag | Meaning |
|---|---|
--root |
The module path (root_key) to diff. Defaults to the module of the registered checkout enclosing the working directory (the nearest go.mod); outside one, it is required with a range. |
--location |
The registered checkout to resolve and index revisions from, so HEAD and branch names mean that worktree's. Defaults to the checkout enclosing the working directory when it belongs to --root, else the primary checkout. A relative or symlinked path is canonicalized. |
--visibility |
exported (default), internal, or all. A row is kept when the symbol's visibility on either side matches, except a structure row, which internal and all keep whatever the symbol's visibility and exported never does. |
--change-type |
The row classes to report: added, removed, signature, structure, body, format, moved, import. Repeatable or comma separated, with commons MatchItems patterns: * wildcards and ! exclusions, which win (--change-type '!format,!import' removes layout and import rows). Default all. It filters rows after symbols are paired, so it never changes a row's class; filtered rows count as hidden. A file left without a row is omitted and counted in its package's hidden_files (whose totals still include it), and a package left without a file is omitted. A pattern that matches no class fails. |
--untracked |
With a single revision, also compare the worktree's untracked files that are not ignored, as new files (see comparing with the worktree). |
--stat |
Adds per-package, per-file, and per-symbol +added -removed counts. Requires readable Git blobs, or for an external root the source blobs its publications stored. |
--snapshot-from, --snapshot-to |
Use this snapshot for that side instead of the newest clean one. The snapshot must belong to the root and record that commit as its revision. |
--auto-index |
Select or generate a clean snapshot for each commit under the current standalone module configuration. Historical indexing reads the commit's go.mod and go.sum with GOWORK=off, so the current workspace cannot replace dependencies or hide the historical module. It leaves registered checkout files and heads untouched. |
--include-tests |
Include Go test symbols in snapshots generated with --auto-index. Without it, test files are excluded, matching the usual indexing default. |
The command is a Clicky operation, so --format json, --format yaml, --format markdown, and --format html all render the same typed result, and uir serve exposes it as POST /api/v1/modules/diff with a body such as {"args": ["<from>..<to>"], "root": "example.org/service", "visibility": "all", "stat": true, "auto-index": true}. uir history [--root <module>] [--location <checkout>] and GET /api/v1/modules/history list local branches, recent commits, and up to 50 pull request refs from origin for the browser's History view. A pr:<number> revision fetches that pull request head from origin when selected. On the command line --root and --location default from the working directory as for uir diff; over HTTP the server's working directory is not the caller's, so root is required.
To inspect one Git commit as change history, use uir history show <commit> [--root <module>]. It compares that commit with its first parent, indexes either missing clean snapshot on demand, and shows all symbol changes with line counts by default. --visibility exported|internal|all, --change-type, --include-tests, and --stat=false control the result. An initial commit has no parent and returns an error; use uir diff with an explicit range when comparing other revisions.
uir history show HEAD --root example.org/ledger# from inside a registered checkout of example.org/ledger
uir diff HEAD~1..HEAD --visibility all --stat--patch emits complete original Git hunks selected by --visibility and --change-type. It supports stdin, worktree comparisons and Git commit ranges. It writes patch bytes only; it does not stage changes. A hunk mixing selected edits with other edits fails before any output. Use smaller input hunks (git diff -U0; apply these with git apply --unidiff-zero) or separate the edits first. Fully selected file additions/deletions include package/import scaffolding and declaration separators.
mkdir -p .tmp
git diff --full-index --no-renames | uir diff --patch --visibility all --change-type moved,renamed > .tmp/refactors.patch
git apply --cached --check .tmp/refactors.patch
git apply --cached .tmp/refactors.patchUse git diff to base the patch on the current index and preserve existing staged changes. uir diff HEAD --patch --untracked instead compares HEAD with the worktree, including untracked destinations; its patch requires an index matching that base. No matches emit an empty patch successfully. --patch is incompatible with formatted output, --stat, HTTP requests and external roots without Git hunks.
renamed pairs unique Go declarations whose tokens differ only in their own declared name and resolved self references, with unchanged visibility and implementation. The row exposes name_before and its current name. Ambiguous candidates remain added/removed. Selected renames also include original reference-only edits proven by Go symbol resolution. Unresolved references are not selected by spelling, and a selected reference line containing other edits is rejected. No edits outside the supplied comparison are synthesized.
uir diff <rev> is git diff <rev>: it runs git diff --full-index --no-renames <commit> in the checkout the revision resolved in (the current checkout, or --location) and diffs that patch as below, without the index. A pure rename would carry no blob ids, and symbols pair across files on their own. from.commit is the resolved commit and to.commit is worktree when any side was read from the worktree. --snapshot-from, --snapshot-to, --auto-index, and --include-tests apply to two commits and fail with a single revision; over HTTP a single revision is refused, because the server's worktree is not the caller's.
Untracked files are not part of it, as with git, unless --untracked is set. Then the diff runs against a temporary copy of the index (GIT_INDEX_FILE) in which every file git ls-files --others --exclude-standard lists is marked intent-to-add, so those files appear as new files and a symbol moved into one pairs as moved. The checkout's own index is never written. --untracked with a range or a patch on stdin fails.
A single revision needs no index, so outside every registered checkout, with neither --root nor --location, it is resolved and diffed in the git repository holding the working directory, and the root is that repository's go.mod module, as for a patch. A range there still requires a registered checkout (uir add .) or --root, because it compares indexed snapshots.
uir diff HEAD --visibility all --untracked --change-type '!added,!removed'Without a range, or with -, uir diff reads a git patch from stdin and reports the same result for it, with no database and no indexing:
git diff HEAD~3 | uir diff
git diff | uir diff --stat --visibility all- Bytes. Each side of a file is the blob its
index <old>..<new>line names, read in the repository holding the working directory (git rev-parse --show-toplevel). Every id of the patch, abbreviated or full, is written to onegit cat-file --batchprocess and its answers are read in order, so a patch of any size costs the same few git processes. An all-zero id is an absent side and is never sent to git. An old side git does not have, an ambiguous abbreviated id (produce the patch with--full-index), or an id that names something other than a blob fails the command, naming the path and id. A new side git does not have is a worktree file (git diffwithout--cached): it is read from the worktree, and all such files are hashed by onegit hash-object --stdin-pathsprocess; each must still hash to the patch's id, otherwise the command fails withworktree changed since the patch was produced. The result'sto.commitis thenworktree, elsepatch:new;from.commitispatch:old. In Go,symboldiff.DiffPatchreads the sides through aSourceLocator;symboldiff.NewGitLocatoris the one described here. - Packages. A file's package is the nearest
go.modabove it in the worktree joined with its directory below that module; the root is the module of the top-levelgo.mod. A file outside every module, or a repository without a top-levelgo.mod, fails the command. - Symbols. Go files are extracted from syntax alone (
syntax.Document, inindexer/syntax), so every file and row carries thesyntaxmarker, and shapes are the canonical UIR layer shapes (method public (a (int)) ( (int))) rather than go/types-printed ones. Unlike asyntaxdocument in the index, each symbol's public and private hashes are computed from its extracted node, so rows still classify assignatureandstructure. Package-levelvarandconstdeclarations are symbols too: the shape is the declared type alone (package_variable (int) public, orpackage_variable publicwhen untyped), so a changed value isbodyand a changed typesignature. Symbols are matched by a stand-in for the canonical id: the identity key with a function's signature reduced to its parameter types, so a parameter rename is asignaturerow and a parameter-type change is a groupedremovedplusadded, as with an index. - Files. A rename is the removal of its old path and the addition of its new one, so its unchanged symbols are
moved. A file that is not Go source is listed withexcluded: not Go sourceand no rows. A mode-only change is skipped. With--stat, lines are attributed from the same bytes; there is no manifest comparison. - Refused input. A plain
diff -uwithoutindexlines, a rename at 100% similarity (git writes noindexline for it; usegit diff --no-renames), copies (-C), and combined merge diffs fail.--root,--snapshot-from,--snapshot-to,--auto-index,--include-tests, and--locationapply to a range and fail with a patch. Over HTTP a patch is refused: there is no stdin, and the server's working directory is not the caller's.
For each commit the diff takes the root's snapshots whose revision equals the commit (through the (root_id, revision) index) and picks the newest whose worktree_state is clean. Indexing records clean only when git status --porcelain under the module is empty and every indexed file is tracked by Git. Untracked files that Git does not ignore are indexed and make the snapshot dirty; Git-ignored files are excluded from discovery. This keeps a clean snapshot's source bytes equal to the commit's bytes.
- No snapshot for the commit: without
--auto-index, the diff fails and says the commit must be indexed first. With--auto-index, it creates a clean standalone snapshot from a temporary worktree. - Only
dirtysnapshots: without--auto-index, the diff fails and names them, because a dirty snapshot's bytes may not be the commit's bytes. With--auto-index, it creates a clean standalone snapshot. Pass--snapshot-fromor--snapshot-toto use a dirty snapshot explicitly;--statthen verifies each file's blob against the snapshot and reports the files whose bytes differ. - Different
configuration_hashon the two selected snapshots (another indexer version,GOOS,GOARCH,CGO_ENABLED, toolchain, or tags): the diff fails, because shape and body hashes are only comparable under one configuration.--auto-indexselects or generates both sides under the current standalone configuration.
Both snapshots' active documents are derived with storage.ActiveDocuments without their content: changed-file detection compares document headers only (id, ordinal, coverage, revision). A path whose document id is equal on both sides is skipped without being read. A path present on one side only is an added or removed file. A path whose document changed only because a sibling in its package changed (same bytes, new input hash) is a changed file, but its symbols' fingerprints compare equal, so without --stat it is omitted without its document being decoded.
Symbols are matched across the whole diff by identity, so a symbol that moved to another file is still one symbol. For changed indexed documents outside a package that is syntax or partial on either side, classification reads no document: both snapshots' effective symbols (storage.EffectiveSymbols, from the symbol deltas) give each defined symbol's public, private, and content fingerprints, the first eight bytes of its public_hash, private_hash, and content_hash, and the definition postings of each side's changed documents say which of them define each symbol. A symbol declared once on each side it appears on is classified by its handle:
| Class | Condition |
|---|---|
added |
only on the new side |
removed |
only on the old side |
signature |
both sides, public fingerprint differs |
structure |
public fingerprint equal, private fingerprint differs |
body |
public and private fingerprints equal, content fingerprint differs |
moved |
fingerprints equal, defining path_key differs |
format |
fingerprints and path equal, the declaration's source bytes differ (comments, whitespace, layout) |
import |
a file on both sides imports a path under an alias the other side does not, or under another path |
| omitted | fingerprints, path, and source bytes equal |
The three layers nest (a public change is always a private change), so the class names the outermost layer that changed, and a row carries no separate layer field:
| Class | Layer | What changed | Go example | SQL example |
|---|---|---|---|---|
signature |
public | what code outside the symbol's visibility boundary observes | a parameter, a result, an exported field | a table's output columns, a procedure's parameters |
structure |
private | the full declared structure only | an unexported field added to an exported struct that already had one (the public shape's opaque line stands for every unexported field) |
an index, a foreign key, a default |
body |
content | the implementation only | a function body | a view definition, a procedure or trigger body |
A package with a syntax or partial changed document on either side, and a symbol an external producer declares more than once on a side, are matched over their decoded documents instead: first by canonical symbol id, then by key wherever one side has no id (a syntax document, or an unproven declaration in a partial document). Each Go func init has its own file-and-ordinal discriminator and canonical id. Those rows use the same classes and compare the full public_hash, private_hash, and content_hash; when either side has no id the public and private hashes are not comparable, so such a pair can only be body or moved.
A document is decoded only when the output needs it. With --stat, every changed document is read, for its symbol extents. Otherwise the diff reads the documents of syntax, partial, and excluded files, both sides of a symbol declared more than once, and, for a row the visibility filter shows, the new side of an added symbol, the old side of a removed one, and both sides of a signature or structure change, whose shapes the row prints. With --visibility internal or all, both sides of every changed file on both sides are read too, for their imports. A shown body or moved row prints no shape and is named from the symbols row and its owners' names. The chosen documents' content is loaded in one batched read (storage.DocumentContents).
content_hash digests the declaration's tokens without comments, whitespace, or layout tokens, with the names it binds renamed to their positions (content layer), so a comment added inside a function, a re-wrapped call, gofmt, or a renamed local leaves every hash equal. Such a symbol whose source bytes did change is a format row, kept apart from body so --change-type '!format' drops it. A patch diff compares the extents' bytes directly and reports format rows with or without --stat; a commit-to-commit diff has the bytes only from blobs, so it reports them only with --stat, when the symbol's line counts are nonzero.
Imports are not symbols, and a syntax shape names a package by its alias (cel.Env), so a module path change behind an unchanged alias leaves every hash equal. Each document records its file's imports (alias and path, format 11), and a file on both sides gets one import row per alias whose path changed or that one side alone imports (a blank or dot import is keyed by its path): shape_before and shape_after are the paths. Reordering an import block reports nothing, and an added or removed file's imports are not reported. An import binds a name in its file only, so its visibility is internal: import rows are shown by --visibility internal and all, never by exported. A commit-to-commit diff that shows them reads both sides' documents of every changed file on both sides.
A unique pure Go declaration rename is renamed, with name_before recording its old name. Ambiguous candidates remain removed plus added, because the name is part of the identity. A parameter-type change is also removed plus added, because parameter types are part of the identity; when exactly one removed and one added symbol share package, kind, owner, and name, both rows carry the same group, and the added row carries the old shape and a shape diff against it, so the change reads as one signature edit.
A move to another package changes the identity too, because the package is part of it. After identity matching, the removed and added symbols are grouped by kind, owner, and name; a group of exactly one removed and one added symbol in different packages is paired when their full shapes are equal once the qualifiers naming either package (by its last import path element) are removed, since a move turns models.Item into Item and back. Both documents are read for it, and the pair is classified by its layer hashes like any other: moved only when nothing but its file changed, otherwise signature, structure, or body. moved is a pure move; a symbol that moved and changed keeps its changed class and is still reported under both files. The output never guesses other pairings: a name with two candidates on either side stays removed plus added.
A row has kind, owner, name, visibility, both shapes when they differ, both paths, line counts with --stat, and coverage markers. A signature row's shapes are the public shapes (public_shape), so a Go struct shows its exported fields and opaque; every other row's shapes are the private (full) shapes (shape). It is reported under its new file, or under its old file when removed. A symbol paired across two files (a moved row, or a change whose defining file also changed) is reported under both: the row under its new file names the file it came from, and a copy with moved_away: true under its old file names the file it went to, so neither file appears to have silently lost or gained it. The copy carries no line counts; the symbol's lines count under its new file only. Renamed or retyped symbols and cross-package candidates that cannot be paired remain removed plus added. Nested symbols (struct fields, interface methods) are rows of their own, but their lines belong to the outermost declaration that contains them, so they carry no line counts.
| Marker | Meaning |
|---|---|
partial |
The package type-checked with errors on either side. Only proven symbols have ids; unproven ones are matched by key, and a symbol missing from a partial side may be unproven rather than removed. |
syntax |
The package did not type-check on either side. Symbols are matched by key and can only be added, removed, body, or moved. |
excluded |
The file is not extracted (build constraints) on either side. All of its lines are file scope; symbols the other side declares are reported without line counts. |
manifest |
go.mod or go.sum differs between the two commits (with --stat only). It has no rows; its whole diff is file scope. |
With --stat, each changed file's bytes are read at both commits with git cat-file -p <commit>:./<path> in a registered checkout of the root that contains the commit (the primary location first, then any other location where git rev-parse --verify <commit>^{commit} succeeds). Each blob is hashed with SHA-256, as the indexer hashes source files, and must equal the source revision's content_hash.
Each side of a file is cut into segments: one per outermost symbol extent (widened to whole lines when nothing else shares them), plus a single (file scope) segment of everything between them: the package clause, imports, free comments, and blank lines. Segments are paired by symbol id (or key), the two file-scope segments are paired with each other, and each pair is line-diffed with a Myers diff. A symbol on one side only counts all of its lines as added or removed. A moved symbol is diffed against its old extent and counted under its new file.
A file's total is the sum of every row reported under it, hidden rows included, plus its file scope; a package's total is the sum of its files. For a file without moved symbols this is normally what git diff --numstat reports; the two can differ when Git's whole-file diff aligns lines across a declaration boundary, which a per-segment diff never does.
example.org/ledger old..new
╰── 📦 example.org/ledger/money +5 -3
╰── ✏️ money/money.go (modified) +5 -3
├── ✏️ Scale signature +1 -1
│ ╰── - func Scale(a Amount, factor int) Amount
│ + func Scale(a Amount, by int) Amount
├── 💻 Format body +4 -2
╰── (file scope) +0 -0
A signature row shows a shape diff of the public shapes, and a structure row one of the private shapes. The tree groups those lines beneath their symbol; change icons identify each file and symbol class. With --stat, the + and - counts on body rows show changed content lines, and ANSI colors distinguish additions from removals. The two canonical shapes are line-diffed with Myers, treating lines that differ only in whitespace (gofmt realignment) as equal. Within a changed hunk, the i-th removed line and the i-th added line are a replaced pair when they share at least one non-blank token, and are token-diffed; short equal runs between edits are folded into the edit so a changed tail reads as one replacement. A Go root's lines are split into go/scanner tokens (tokenizer go). An external root's shapes are not Go, so they are split language-neutrally (tokenizer text): identifiers (which may start with @, #, or $), numbers, quoted strings and identifiers ('…', "…", `…`), and runs of any other non-space characters.
The plain form (non-TTY output, String()) prints unchanged lines with two spaces, removed lines with - , and added lines with + . The rich forms print a replaced pair as one ~ line with token marks, through clicky api.Text: removed tokens red and struck through, added tokens green and bold. In a terminal that is ANSI; in markdown func Scale(a Amount, ~~factor~~**by** int) Amount (wrapped in colour spans unless colour is off); in HTML clicky's <s> and <strong>. JSON carries the structured form: shape_diff is a list of lines {op, text, paired, tokenizer, tokens: [{op, text}]}, where op is equal, delete, or insert, a paired line names the tokenizer (go or text) its tokens were split by, and a paired delete line's tokens are its equal and deleted runs while the paired insert line's are its equal and inserted runs.
--visibility exported hides internal rows and structure rows, and --change-type hides rows of other classes, but neither hides their lines: a file with hidden rows says (N hidden rows) and its totals still include them, so the totals never silently add up to less than the file's diff.
A root whose locations are all external (a non-Go producer's URI, registered by uir import / indexer.Publish) is diffed without Git. A root is either Go or external; one that mixes the two location kinds fails.
- Revisions.
<from>and<to>are taken literally, never resolved withgit rev-parse: each must equal a published snapshot'srevisionorgit_commit(for exampleschema-v1..schema-v2, orschema-v1 schema-v2). Only those two forms are accepted:A...B,A.., a single revision, and the other Git forms fail with a message asking for<from>..<to>. An unknown revision fails, naming it and the root. - Snapshots. Each side is the newest
importorhistoricalsnapshot of its revision. A producer's snapshot has no worktree to be clean or dirty, so itsworktree_state(unknown) is not checked.--snapshot-fromand--snapshot-towork as for a Go root. - Line counts. With
--stat, each file's bytes are the source blob its publication stored under the source revision'scontent_hash, verified against that hash;checkoutis empty. An external root has no manifests. - Shape diffs use the language-neutral tokenizer.
- No Git history.
--auto-indexfails, because a producer's revision cannot be indexed from Git: republish it withuir import.uir historyanduir history showfail too; compare two published revisions withuir diff.
uir import schema-v1.json
uir import schema-v2.json
uir diff schema-v1..schema-v2 --root example.org/schema --visibility all --stat| Failure | Effect |
|---|---|
Empty revision, malformed range, unknown --visibility, unknown root |
The command fails. |
| Revision that no checkout resolves | The command fails; pass the full commit hash. |
External root: revision with no published snapshot, --auto-index, or uir history |
The command fails, naming the revision or saying the root is published by an external producer. |
External root: no stored blob under a source's content hash, or a blob whose hash differs (--stat) |
That file's lines_error says so; its rows are still reported. |
| Commit with no snapshot, or only dirty snapshots | The command fails and names the commit or the dirty snapshots. |
| Override snapshot of another root or another revision | The command fails. |
| Different configuration hashes | The command fails. |
| A symbol that a changed document defines is not effective on exactly the sides whose changed documents define it, or a symbol whose effective fingerprints differ is declared by no changed document | The command fails naming the symbol handle, because the symbol deltas are inconsistent with the documents. |
No registered checkout contains a commit (--stat) |
The result's lines_error and every file's lines_error say so; symbol rows are still reported, and manifests are not compared. |
Blob unreadable, or its hash differs from the source revision (--stat) |
That file's lines_error states the path, commit, and both hashes; its rows are reported without counts, and every other file completes. A moved symbol whose other file failed fails its destination file's counts with the reason. |
Manifest on a dirty snapshot (--stat) |
The manifest's lines_error says its bytes cannot be verified. |
- The package-level
export_shape_hashpre-check that the design suggests for skipping packages under--visibility exportedis not applied: skipping would hide exportedbodyrows and line counts, so every changed package is read.
The History page compares any two selected branches, commits, or pull request heads. The Git log shows recent commits; selecting one compares it with its first parent and displays changed packages, files, symbol rows, signatures, and line counts. Comparison choices and the selected log commit are kept in the URL.