2.6 KiB
2.6 KiB
Query Languages
Use jj's query languages when you need to select revisions, paths, or render compact output without falling back to the default verbose UI.
Tested with jj 0.41.0
Revsets
Use revsets to select commits and workspaces.
Common selectors:
@: current working-copy change@-: parent of the current working-copy changetrunk(): configured mainline; use this instead of guessingmainvsmaster::@: all ancestors of@trunk()..@: work reachable from@that is not ontrunk()working_copies(): all workspace working-copy commits<workspace>@: another workspace's working-copy commit<change-id>: a stable change ID such aswqzktpqm
Agent patterns:
# Current work relative to trunk
jj --no-pager log -r 'trunk()..@'
# All active workspace tips
jj --no-pager log -r 'working_copies()'
# One specific workspace tip
jj --no-pager log -r '<workspace>@'
Quote revsets that contain punctuation or function calls.
Filesets
Use filesets when a command should operate on only part of the tree.
Common patterns:
pathor"path": cwd-relative path prefixfile:"path": exact cwd-relative file pathglob:"pattern": cwd-relative globroot:"path": workspace-relative path prefix~x: everything exceptxx & y: intersectionx | y: unionx ~ y: subtractyfromx
Examples:
# Only markdown files in the current directory
jj diff 'glob:"*.md"'
# Everything in src except snapshots
jj diff 'src ~ glob:"src/**/*.snap"'
# Exact file path
jj diff 'file:"README.md"'
Templates
Use templates when default output is too large or too decorative for agent work.
Common building blocks:
++: concatenate output piecesif(cond, a, b): conditional formattingdescription.first_line(): one-line summarychange_id.shortest(8): stable short IDbookmarks: bookmark names for a commitcurrent_working_copy,empty,conflict: useful booleans injj log
Example:
jj --no-pager log --no-graph -n 5 -T 'change_id.shortest(8) ++ " " ++ if(description, description.first_line(), "(no description)") ++ "\n"'
Start from references/TEMPLATES.md instead of inventing new templates unless you need something substantially different.
Rules
- Prefer
trunk()over hardcodingmainormaster. - Quote revsets and filesets in shell commands when punctuation could be interpreted by the shell.
- Prefer compact
jj --no-pagerinspection commands before widening the query. - If a query fails to parse, check
jj <command> --help,jj help -k revsets,jj help -k filesets, orjj help -k templates.