| 1 |
# Revsets |
| 2 |
|
| 3 |
Jujutsu supports a functional language for selecting a set of revisions. |
| 4 |
Expressions in this language are called "revsets" (the idea comes from |
| 5 |
[Mercurial](https://www.mercurial-scm.org/repo/hg/help/revsets)). The language |
| 6 |
consists of symbols, operators, and functions. |
| 7 |
|
| 8 |
Most `jj` commands accept a revset (or multiple). Many commands, such as |
| 9 |
`jj edit <revset>` expect the revset to resolve to a single commit; it is an |
| 10 |
error to pass a revset that resolves to more than one commit (or zero commits) |
| 11 |
to such commands. |
| 12 |
|
| 13 |
The words "revisions" and "commits" are used interchangeably in this document. |
| 14 |
|
| 15 |
## Hidden revisions |
| 16 |
|
| 17 |
Most revsets search only the [visible commits](glossary.md#visible-commits). |
| 18 |
Other commits are only included if you explicitly mention them (e.g. by commit |
| 19 |
ID, `<name>@<remote>` symbol, or `at_operation()` function). |
| 20 |
|
| 21 |
If hidden commits are specified, their ancestors also become available to the |
| 22 |
search space. They are included in `all()`, `x..`, `~x`, etc., but not in |
| 23 |
`..visible_heads()`, etc. For example, `hidden_id | all()` is equivalent to |
| 24 |
`hidden_id | ::(hidden_id | visible_heads())`. |
| 25 |
|
| 26 |
## Symbols |
| 27 |
|
| 28 |
The `@` expression refers to the working copy commit in the current workspace. |
| 29 |
Use `<workspace name>@` to refer to the working-copy commit in another |
| 30 |
workspace. Use `<name>@<remote>` to refer to a remote-tracking tag / bookmark. |
| 31 |
|
| 32 |
A full commit ID refers to a single commit. A unique prefix of the full commit |
| 33 |
ID can also be used. It is an error to use a non-unique prefix. |
| 34 |
|
| 35 |
A full change ID refers to a visible commit with that change ID. A unique prefix |
| 36 |
of the full change ID can also be used. It is an error to use a non-unique |
| 37 |
prefix or [a divergent change ID][divergent-change]. To refer to a |
| 38 |
[hidden](#hidden-revisions) commit or [divergent change][divergent-change], a |
| 39 |
[change offset][change-offset] can be added using `<change ID>/<offset>` syntax. |
| 40 |
|
| 41 |
Use [single or double quotes][string-literals] to prevent a symbol from being |
| 42 |
interpreted as an expression. For example, `"x-"` is the symbol `x-`, not the |
| 43 |
parents of symbol `x`. Taking shell quoting into account, you may need to use |
| 44 |
something like `jj log -r '"x-"'`. |
| 45 |
|
| 46 |
[divergent-change]: glossary.md#divergent-change |
| 47 |
[change-offset]: glossary.md#change-offset |
| 48 |
[string-literals]: templates.md#stringliteral-type |
| 49 |
|
| 50 |
### Priority |
| 51 |
|
| 52 |
Jujutsu attempts to resolve a symbol in the following order: |
| 53 |
|
| 54 |
1. Tag name |
| 55 |
2. Bookmark name |
| 56 |
3. Commit ID or change ID |
| 57 |
|
| 58 |
To override the priority, use the appropriate [revset function](#functions). For |
| 59 |
example, to resolve `abc` as a commit ID even if there happens to be a bookmark |
| 60 |
by the same name, use `commit_id(abc)`. This is particularly useful in scripts. |
| 61 |
|
| 62 |
## Operators |
| 63 |
|
| 64 |
The following operators are supported. `x` and `y` below can be any revset, not |
| 65 |
only symbols. |
| 66 |
|
| 67 |
Operators are listed in order of binding power from strongest to weakest, e.g. |
| 68 |
`x | y & z` is interpreted as `x | (y & z)` since `&` has stronger binding power |
| 69 |
than `|`. Infix operators of the same binding power are parsed from left to |
| 70 |
right, e.g. `x ~ y & z` is interpreted as `(x ~ y) & z` rather than `x ~ (y & |
| 71 |
z)`. |
| 72 |
|
| 73 |
As seen above, parentheses can be used to control evaluation order, e.g. `(x & |
| 74 |
y) | z` or `x & (y | z)`. |
| 75 |
|
| 76 |
<!-- The following list is based on `PRATT` in `revset_parser.rs`. --> |
| 77 |
|
| 78 |
1. * `f(x)`: Function call. |
| 79 |
|
| 80 |
2. * `x-`: Parents of `x`, can be empty. |
| 81 |
* `x+`: Children of `x`, can be empty. |
| 82 |
|
| 83 |
3. * `p:x`: String/date pattern or pattern alias named `p`. |
| 84 |
|
| 85 |
4. * `x::`: Descendants of `x`, including the commits in `x` itself. Equivalent to |
| 86 |
`x::visible_heads()` if no hidden revisions are mentioned. |
| 87 |
* `x..`: Revisions that are not ancestors of `x`. Equivalent to `~::x`, and |
| 88 |
`x..visible_heads()` if no hidden revisions are mentioned. |
| 89 |
* `::x`: Ancestors of `x`, including the commits in `x` itself. Shorthand for |
| 90 |
`root()::x`. |
| 91 |
* `..x`: Ancestors of `x`, including the commits in `x` itself, but excluding |
| 92 |
the root commit. Shorthand for `root()..x`. Equivalent to `::x ~ root()`. |
| 93 |
* `x::y`: Descendants of `x` that are also ancestors of `y`. Equivalent |
| 94 |
to `x:: & ::y`. This is what `git log` calls `--ancestry-path x..y`. |
| 95 |
* `x..y`: Ancestors of `y` that are not also ancestors of `x`. Equivalent to |
| 96 |
`::y ~ ::x`. This is what `git log` calls `x..y` (i.e. the same as we call it). |
| 97 |
Note that this is *not* a "path" between `x` and `y` in the commit graph -- `x` |
| 98 |
and `y` do not need to be related by ancestry. |
| 99 |
* `::`: All visible commits in the repo. Equivalent to `all()`, and |
| 100 |
`root()::visible_heads()` if no hidden revisions are mentioned. |
| 101 |
* `..`: All visible commits in the repo, but excluding the root commit. |
| 102 |
Equivalent to `~root()`, and `root()..visible_heads()` if no hidden revisions |
| 103 |
are mentioned. |
| 104 |
|
| 105 |
5. * `~x`: Revisions that are not in `x`. |
| 106 |
|
| 107 |
6. * `x & y`: Revisions that are in both `x` and `y`. |
| 108 |
* `x ~ y`: Revisions that are in `x` but not in `y`. |
| 109 |
|
| 110 |
7. * `x | y`: Revisions that are in either `x` or `y` (or both). |
| 111 |
|
| 112 |
**Note:** The `..` operator does not distribute over union (`|`) on its left |
| 113 |
side. For example, `(A | B)..` is **not** equivalent to `A.. | B..`. The |
| 114 |
expression `(A | B)..` means "commits that are not ancestors of A *and* not |
| 115 |
ancestors of B", while `A.. | B..` means "commits that are not ancestors of A |
| 116 |
*or* not ancestors of B". In fact, `(A | B).. = A.. & B..`. See the examples |
| 117 |
below for concrete illustrations. |
| 118 |
|
| 119 |
<!-- The following format will be understood by the web site generator, and will |
| 120 |
generate a folded section that can be unfolded at will. --> |
| 121 |
|
| 122 |
??? examples |
| 123 |
|
| 124 |
Given this history: |
| 125 |
``` |
| 126 |
D |
| 127 |
|\ |
| 128 |
B C |
| 129 |
|/ |
| 130 |
A |
| 131 |
| |
| 132 |
root() |
| 133 |
``` |
| 134 |
|
| 135 |
**Operator** `x-` |
| 136 |
|
| 137 |
* `D-` ⇒ `{C,B}` |
| 138 |
* `B-` ⇒ `{A}` |
| 139 |
* `A-` ⇒ `{root()}` |
| 140 |
* `root()-` ⇒ `{}` (empty set) |
| 141 |
* `none()-` ⇒ `{}` (empty set) |
| 142 |
* `(D|A)-` ⇒ `{C,B,root()}` |
| 143 |
* `(C|B)-` ⇒ `{A}` |
| 144 |
|
| 145 |
**Operator** `x+` |
| 146 |
|
| 147 |
* `D+` ⇒ `{}` (empty set) |
| 148 |
* `B+` ⇒ `{D}` |
| 149 |
* `A+` ⇒ `{B,C}` |
| 150 |
* `root()+` ⇒ `{A}` |
| 151 |
* `none()+` ⇒ `{}` (empty set) |
| 152 |
* `(C|B)+` ⇒ `{D}` |
| 153 |
* `(B|root())+` ⇒ `{D,A}` |
| 154 |
|
| 155 |
**Operator** `x::` |
| 156 |
|
| 157 |
* `D::` ⇒ `{D}` |
| 158 |
* `B::` ⇒ `{D,B}` |
| 159 |
* `A::` ⇒ `{D,C,B,A}` |
| 160 |
* `root()::` ⇒ `{D,C,B,A,root()}` |
| 161 |
* `none()::` ⇒ `{}` (empty set) |
| 162 |
* `(C|B)::` ⇒ `{D,C,B}` |
| 163 |
|
| 164 |
**Operator** `x..` |
| 165 |
|
| 166 |
* `D..` ⇒ `{}` (empty set) |
| 167 |
* `B..` ⇒ `{D,C}` (note that, unlike `B::`, this includes `C`) |
| 168 |
* `A..` ⇒ `{D,C,B}` |
| 169 |
* `root()..` ⇒ `{D,C,B,A}` |
| 170 |
* `none()..` ⇒ `{D,C,B,A,root()}` |
| 171 |
* `(C|B)..` ⇒ `{D}` |
| 172 |
|
| 173 |
**Operator** `::x` |
| 174 |
|
| 175 |
* `::D` ⇒ `{D,C,B,A,root()}` |
| 176 |
* `::B` ⇒ `{B,A,root()}` |
| 177 |
* `::A` ⇒ `{A,root()}` |
| 178 |
* `::root()` ⇒ `{root()}` |
| 179 |
* `::none()` ⇒ `{}` (empty set) |
| 180 |
* `::(C|B)` ⇒ `{C,B,A,root()}` |
| 181 |
|
| 182 |
**Operator** `..x` |
| 183 |
|
| 184 |
* `..D` ⇒ `{D,C,B,A}` |
| 185 |
* `..B` ⇒ `{B,A}` |
| 186 |
* `..A` ⇒ `{A}` |
| 187 |
* `..root()` ⇒ `{}` (empty set) |
| 188 |
* `..none()` ⇒ `{}` (empty set) |
| 189 |
* `..(C|B)` ⇒ `{C,B,A}` |
| 190 |
|
| 191 |
**Operator** `x::y` |
| 192 |
|
| 193 |
* `D::D` ⇒ `{D}` |
| 194 |
* `B::D` ⇒ `{D,B}` (note that, unlike `B..D`, this includes `B` and excludes `C`) |
| 195 |
* `B::C` ⇒ `{}` (empty set) (note that, unlike `B..C`, this excludes `C`) |
| 196 |
* `A::D` ⇒ `{D,C,B,A}` |
| 197 |
* `root()::D` ⇒ `{D,C,B,A,root()}` |
| 198 |
* `none()::D` ⇒ `{}` (empty set) |
| 199 |
* `D::B` ⇒ `{}` (empty set) |
| 200 |
* `(C|B)::(C|B)` ⇒ `{C,B}` |
| 201 |
|
| 202 |
**Operator** `x..y` |
| 203 |
|
| 204 |
* `D..D` ⇒ `{}` (empty set) |
| 205 |
* `B..D` ⇒ `{D,C}` (note that, unlike `B::D`, this includes `C` and excludes `B`) |
| 206 |
* `B..C` ⇒ `{C}` (note that, unlike `B::C`, this includes `C`) |
| 207 |
* `A..D` ⇒ `{D,C,B}` |
| 208 |
* `root()..D` ⇒ `{D,C,B,A}` |
| 209 |
* `none()..D` ⇒ `{D,C,B,A,root()}` |
| 210 |
* `D..B` ⇒ `{}` (empty set) |
| 211 |
* `(C|B)..(C|B)` ⇒ `{}` (empty set) |
| 212 |
|
| 213 |
**Non-distributivity of `..` over union (left side)** |
| 214 |
|
| 215 |
Using the same graph, observe that `(C|B)..` ⇒ `{D}`, but: |
| 216 |
* `C..` ⇒ `{D,B}` |
| 217 |
* `B..` ⇒ `{D,C}` |
| 218 |
* `C.. | B..` ⇒ `{D,C,B}` |
| 219 |
* `C.. & B..` ⇒ `{D}` |
| 220 |
|
| 221 |
So `(C|B)..` ≠ `C.. | B..`, but `(C|B).. = C.. & B..`. The `..` operator |
| 222 |
converts union to intersection on its left side. |
| 223 |
|
| 224 |
## Functions |
| 225 |
|
| 226 |
You can also specify revisions by using functions. Some functions take other |
| 227 |
revsets (expressions) as arguments. |
| 228 |
|
| 229 |
??? note "Function argument syntax" |
| 230 |
|
| 231 |
In this documentation, optional arguments are indicated with square |
| 232 |
brackets like `[arg]`. Some arguments also have an optional label which can |
| 233 |
be used to specify that argument without specifying all previous arguments. |
| 234 |
|
| 235 |
For instance, `remote_bookmarks([name_pattern], [[remote=]remote_pattern])` |
| 236 |
indicates that all of the following usages are valid: |
| 237 |
|
| 238 |
* `remote_bookmarks()` |
| 239 |
* `remote_bookmarks("main")` |
| 240 |
* `remote_bookmarks("main", "origin")` |
| 241 |
* `remote_bookmarks("main", remote="origin")` |
| 242 |
* `remote_bookmarks(remote="origin")` |
| 243 |
|
| 244 |
* `parents(x, [depth])`: `parents(x)` is the same as `x-`. |
| 245 |
`parents(x, depth)` returns the parents of `x` at the given `depth`. For |
| 246 |
instance, `parents(x, 3)` is equivalent to `x---`. |
| 247 |
|
| 248 |
* `children(x, [depth])`: `children(x)` is the same as `x+`. |
| 249 |
`children(x, depth)` returns the children of `x` at the given `depth`. For |
| 250 |
instance, `children(x, 3)` is equivalent to `x+++`. |
| 251 |
|
| 252 |
* `ancestors(x, [depth])`: `ancestors(x)` is the same as `::x`. |
| 253 |
`ancestors(x, depth)` returns the ancestors of `x` limited to the given |
| 254 |
`depth`. |
| 255 |
|
| 256 |
* `descendants(x, [depth])`: `descendants(x)` is the same as `x::`. |
| 257 |
`descendants(x, depth)` returns the descendants of `x` limited to the given |
| 258 |
`depth`. |
| 259 |
|
| 260 |
* `first_parent(x, [depth])`: `first_parent(x)` is similar to `parents(x)`, but |
| 261 |
for merges, it only returns the first parent instead of returning all parents. |
| 262 |
The `depth` argument also works similarly, so `first_parent(x, 2)` is |
| 263 |
equivalent to `first_parent(first_parent(x))`. |
| 264 |
|
| 265 |
* `first_ancestors(x, [depth])`: Similar to `ancestors(x, [depth])`, but only |
| 266 |
traverses the first parent of each commit. In Git, the first parent of a merge |
| 267 |
commit is conventionally the branch into which changes are being merged, so |
| 268 |
`first_ancestors()` can be used to exclude changes made on other branches. |
| 269 |
|
| 270 |
* `reachable(srcs, domain)`: All commits reachable from `srcs`, traversing all |
| 271 |
parent and child edges, such that the entire path is within `domain`. This is |
| 272 |
useful for finding all related commits in a branch or feature without |
| 273 |
traversing outside a defined scope. For example, `reachable(@, mutable())` |
| 274 |
returns the stack of commits you are working on. |
| 275 |
|
| 276 |
* `connected(x)`: Same as `x::x`. Useful when `x` includes several commits. |
| 277 |
|
| 278 |
* `all()`: All visible commits and ancestors of commits explicitly mentioned. |
| 279 |
|
| 280 |
* `none()`: No commits. This function is rarely useful; it is provided for |
| 281 |
completeness. |
| 282 |
|
| 283 |
* `change_id(prefix)`: Commits with the given change ID prefix. If the specified |
| 284 |
change is divergent, this resolves to multiple commits. It is an error to use a |
| 285 |
non-unique prefix. Unmatched prefix isn't an error. |
| 286 |
|
| 287 |
* `commit_id(prefix)`: Commits with the given commit ID prefix. It is an error |
| 288 |
to use a non-unique prefix. Unmatched prefix isn't an error. |
| 289 |
|
| 290 |
* `bookmarks([pattern])`: All local bookmark targets. If `pattern` is specified, |
| 291 |
this selects the bookmarks whose name match the given [string |
| 292 |
pattern](#string-patterns). For example, `bookmarks(*push*)` would match the |
| 293 |
bookmarks `push-123` and `repushed` but not the bookmark `main`. If a bookmark |
| 294 |
is in a conflicted state, all its possible targets are included. |
| 295 |
|
| 296 |
* `remote_bookmarks([name_pattern], [[remote=]remote_pattern])`: All remote |
| 297 |
bookmarks targets across all remotes. If just the `name_pattern` is specified, |
| 298 |
the bookmarks whose names match the given [string pattern](#string-patterns) |
| 299 |
across all remotes are selected. If both `name_pattern` and `remote_pattern` |
| 300 |
are specified, the selection is further restricted to just the remotes whose |
| 301 |
names match `remote_pattern`. |
| 302 |
|
| 303 |
For example, `remote_bookmarks(*push*, *ri*)` would match the bookmarks |
| 304 |
`push-123@origin` and `repushed@private` but not `push-123@upstream` or |
| 305 |
`main@origin` or `main@upstream`. If a bookmark is in a conflicted state, all |
| 306 |
its possible targets are included. |
| 307 |
|
| 308 |
Git-tracking bookmarks are excluded by default. Use `remote="git"` or |
| 309 |
`remote="*"` to select bookmarks including `@git` ones. |
| 310 |
|
| 311 |
* `tracked_remote_bookmarks([name_pattern], [[remote=]remote_pattern])`: All |
| 312 |
targets of tracked remote bookmarks. Supports the same optional arguments as |
| 313 |
`remote_bookmarks()`. |
| 314 |
|
| 315 |
* `untracked_remote_bookmarks([name_pattern], [[remote=]remote_pattern])`: All |
| 316 |
targets of untracked remote bookmarks. Supports the same optional arguments as |
| 317 |
`remote_bookmarks()`. |
| 318 |
|
| 319 |
* `tags([pattern])`: All tag targets. If `pattern` is specified, this selects |
| 320 |
the tags whose name match the given [string pattern](#string-patterns). For |
| 321 |
example, `tags(*v1*)` would match the tags `v123` and `rev1` but not the tag |
| 322 |
`v2`. If a tag is in a conflicted state, all its possible targets are |
| 323 |
included. |
| 324 |
|
| 325 |
* `remote_tags([name_pattern], [[remote=]remote_pattern])`: All remote tags |
| 326 |
targets across all remotes. See `remote_bookmarks()` for arguments. |
| 327 |
|
| 328 |
* `tracked_remote_tags([name_pattern], [[remote=]remote_pattern])`: All targets |
| 329 |
of tracked remote tags. Supports the same optional arguments as |
| 330 |
`remote_tags()`. |
| 331 |
|
| 332 |
* `untracked_remote_tags([name_pattern], [[remote=]remote_pattern])`: All |
| 333 |
targets of untracked remote tags. Supports the same optional arguments as |
| 334 |
`remote_tags()`. |
| 335 |
|
| 336 |
* `visible_heads()`: All visible heads (same as `heads(all())` if no hidden |
| 337 |
revisions are mentioned). |
| 338 |
|
| 339 |
* `root()`: The virtual commit that is the oldest ancestor of all other commits. |
| 340 |
|
| 341 |
* `heads(x)`: Commits in `x` that are not ancestors of other commits in `x`. |
| 342 |
Equivalent to `x ~ ::x-`. Note that this is different from |
| 343 |
[Mercurial's](https://repo.mercurial-scm.org/hg/help/revsets) `heads(x)` |
| 344 |
function, which is equivalent to `x ~ x-`. |
| 345 |
|
| 346 |
* `roots(x)`: Commits in `x` that are not descendants of other commits in `x`. |
| 347 |
Equivalent to `x ~ x+::`. Note that this is different from |
| 348 |
[Mercurial's](https://repo.mercurial-scm.org/hg/help/revsets) `roots(x)` |
| 349 |
function, which is equivalent to `x ~ x+`. |
| 350 |
|
| 351 |
* `latest(x, [count])`: Latest `count` commits in `x`, based on committer |
| 352 |
timestamp. The default `count` is 1. |
| 353 |
|
| 354 |
* `fork_point(x)`: The fork point of all commits in `x`. The fork point is the |
| 355 |
common ancestor(s) of all commits in `x` which do not have any descendants |
| 356 |
that are also common ancestors of all commits in `x`. It is equivalent to |
| 357 |
the revset `heads(::x_1 & ::x_2 & ... & ::x_N)`, where `x_{1..N}` are commits |
| 358 |
in `x`. If `x` resolves to a single commit, `fork_point(x)` resolves to `x`. |
| 359 |
|
| 360 |
* `merge_point(x)`: The merge point of all commits in `x`. Similar to the fork |
| 361 |
point, the merge point is the common descendant(s) of all commits in `x` which |
| 362 |
do not have any ancestors that are also common descendants of all commits in |
| 363 |
`x`. It is equivalent to the revset `roots(x_1:: & x_2:: & ... & x_N::)`, |
| 364 |
where `x_{1..N}` are commits in `x`. If `x` resolves to a single commit, |
| 365 |
`merge_point(x)` resolves to `x`. |
| 366 |
|
| 367 |
* `bisect(x)`: Finds commits in the input set for which about half of the input |
| 368 |
set are descendants. The current implementation deals somewhat poorly with |
| 369 |
non-linear history. |
| 370 |
|
| 371 |
* `exactly(x, count)`: Evaluates `x`, and errors if it is not of exactly size |
| 372 |
`count`. Otherwise, returns `x`. This is useful in particular with `count=1` |
| 373 |
when you want to ensure that some revset expression has exactly one target. |
| 374 |
|
| 375 |
* `merges()`: Merge commits. |
| 376 |
|
| 377 |
* `forks()`: Fork commits, i.e. those with more than 1 child. |
| 378 |
|
| 379 |
* `description(pattern)`: Commits that have a description matching the given |
| 380 |
[string pattern](#string-patterns). |
| 381 |
|
| 382 |
A non-empty description is usually terminated with newline character. For |
| 383 |
example, `description("")` matches commits without description, and |
| 384 |
`description("foo\n")` matches commits with description `"foo\n"`. |
| 385 |
|
| 386 |
* `subject(pattern)`: Commits that have a subject matching the given [string |
| 387 |
pattern](#string-patterns). A subject is the first line of the description |
| 388 |
(without newline character.) |
| 389 |
|
| 390 |
* `author(pattern)`: Commits with the author's name or email matching the given |
| 391 |
[string pattern](#string-patterns). Equivalent to `author_name(pattern) | |
| 392 |
author_email(pattern)`. |
| 393 |
|
| 394 |
* `author_name(pattern)`: Commits with the author's name matching the given |
| 395 |
[string pattern](#string-patterns). |
| 396 |
|
| 397 |
* `author_email(pattern)`: Commits with the author's email matching the given |
| 398 |
[string pattern](#string-patterns). |
| 399 |
|
| 400 |
* `author_date(pattern)`: Commits with [author dates](glossary.md#author-date) |
| 401 |
matching the specified [date pattern](#date-patterns). |
| 402 |
|
| 403 |
* `mine()`: Commits where the author's email matches the email of the current |
| 404 |
user. Equivalent to `author_email(exact-i:<user-email>)` |
| 405 |
|
| 406 |
* `committer(pattern)`: Commits with the committer's name or email matching the |
| 407 |
given [string pattern](#string-patterns). Equivalent to |
| 408 |
`committer_name(pattern) | committer_email(pattern)`. |
| 409 |
|
| 410 |
* `committer_name(pattern)`: Commits with the committer's name matching the |
| 411 |
given [string pattern](#string-patterns). |
| 412 |
|
| 413 |
* `committer_email(pattern)`: Commits with the committer's email matching the |
| 414 |
given [string pattern](#string-patterns). |
| 415 |
|
| 416 |
* `committer_date(pattern)`: Commits with |
| 417 |
[committer dates](glossary.md#committer-date) matching the specified [date |
| 418 |
pattern](#date-patterns). |
| 419 |
|
| 420 |
* `signed()`: Commits that are cryptographically signed. |
| 421 |
|
| 422 |
* `empty()`: Commits modifying no files. This also includes `merges()` without |
| 423 |
user modifications and `root()`. |
| 424 |
|
| 425 |
* `files(expression)`: Commits modifying paths matching the given [fileset |
| 426 |
expression](filesets.md). |
| 427 |
|
| 428 |
Paths are relative to the directory `jj` was invoked from. A directory name |
| 429 |
will match all files in that directory and its subdirectories. |
| 430 |
|
| 431 |
For example, `files(foo)` will match files `foo`, `foo/bar`, `foo/bar/baz`. |
| 432 |
It will *not* match `foobar` or `bar/foo`. |
| 433 |
|
| 434 |
Some file patterns might need quoting because the `expression` must also be |
| 435 |
parsable as a revset. For example, `.` has to be quoted in `files(".")`. |
| 436 |
|
| 437 |
* `diff_lines(text, [files])`: Commits containing diffs matching the given |
| 438 |
`text` pattern line by line. |
| 439 |
|
| 440 |
The search paths can be narrowed by the `files` expression. All modified files |
| 441 |
are scanned by default, but it is likely to change in future version to |
| 442 |
respect the command line path arguments. |
| 443 |
|
| 444 |
For example, `diff_lines("*TODO*", "src")` will search revisions where "TODO" |
| 445 |
is added to or removed from files under "src". |
| 446 |
|
| 447 |
* `diff_lines_added(text, [files])`: like `diff_lines()` above, but matches only |
| 448 |
the "added" side of the diff. |
| 449 |
|
| 450 |
* `diff_lines_removed(text, [files])`: like `diff_lines()` above, but matches |
| 451 |
only the "removed" side of the diff. |
| 452 |
|
| 453 |
* `conflicts()`: Commits that have files in a conflicted state. |
| 454 |
|
| 455 |
* `divergent()`: Commits that are [divergent](glossary.md#divergent-change). |
| 456 |
|
| 457 |
* `present(x)`: Same as `x`, but evaluated to `none()` if any of the commits |
| 458 |
in `x` doesn't exist (e.g. is an unknown bookmark name.) |
| 459 |
|
| 460 |
* `coalesce(revsets...)`: Commits in the first revset in the list of `revsets` |
| 461 |
which does not evaluate to `none()`. If all revsets evaluate to `none()`, then |
| 462 |
the result of `coalesce` will also be `none()`. |
| 463 |
|
| 464 |
* `working_copies()`: The working copy commits across all the workspaces. |
| 465 |
|
| 466 |
* `at_operation(op, x)`: Evaluates `x` at the specified [operation][]. For |
| 467 |
example, `at_operation(@-, visible_heads())` will return all heads which were |
| 468 |
visible at the previous operation. |
| 469 |
|
| 470 |
Since `at_operation(op, x)` brings all commits that were visible at the |
| 471 |
operation to the search space, `at_operation(op, x) | all()` is equivalent to |
| 472 |
`at_operation(op, x) | ::(at_operation(op, x | visible_heads()) | |
| 473 |
visible_heads())`. |
| 474 |
|
| 475 |
[operation]: glossary.md#operation |
| 476 |
|
| 477 |
??? examples |
| 478 |
|
| 479 |
Given this history: |
| 480 |
``` |
| 481 |
E |
| 482 |
| D |
| 483 |
|/| |
| 484 |
B C |
| 485 |
|/ |
| 486 |
A |
| 487 |
| |
| 488 |
root() |
| 489 |
``` |
| 490 |
|
| 491 |
**function** `reachable()` |
| 492 |
|
| 493 |
`reachable(srcs, domain)` finds all commits reachable from `srcs` by |
| 494 |
following parent or child edges, but limited to commits within `domain`. |
| 495 |
|
| 496 |
* `reachable(E, A..)` ⇒ `{E,D,C,B}` — All commits after A are reachable |
| 497 |
* `reachable(E, B..)` ⇒ `{E}` — E is isolated: its only edge (to B) leaves the domain |
| 498 |
* `reachable(C, B..)` ⇒ `{D,C}` — C and D are connected; the C→A edge leaves the domain |
| 499 |
* `reachable(D, B..)` ⇒ `{D,C}` — Same result: D reaches C, but D→B leaves the domain |
| 500 |
* `reachable(A, A..)` ⇒ `{}` (empty set) — A is not in domain `A..`, so it's ignored |
| 501 |
|
| 502 |
**function** `connected()` |
| 503 |
|
| 504 |
* `connected(E|A)` ⇒ `{E,B,A}` |
| 505 |
* `connected(D|A)` ⇒ `{D,C,B,A}` |
| 506 |
* `connected(A)` ⇒ `{A}` |
| 507 |
|
| 508 |
**function** `heads()` |
| 509 |
|
| 510 |
* `heads(E|D)` ⇒ `{E,D}` |
| 511 |
* `heads(E|C)` ⇒ `{E,C}` |
| 512 |
* `heads(E|B)` ⇒ `{E}` |
| 513 |
* `heads(E|A)` ⇒ `{E}` |
| 514 |
* `heads(A)` ⇒ `{A}` |
| 515 |
|
| 516 |
**function** `roots()` |
| 517 |
|
| 518 |
* `roots(E|D)` ⇒ `{E,D}` |
| 519 |
* `roots(E|C)` ⇒ `{E,C}` |
| 520 |
* `roots(E|B)` ⇒ `{B}` |
| 521 |
* `roots(E|A)` ⇒ `{A}` |
| 522 |
* `roots(A)` ⇒ `{A}` |
| 523 |
|
| 524 |
**function** `fork_point()` |
| 525 |
|
| 526 |
* `fork_point(E|D)` ⇒ `{B}` |
| 527 |
* `fork_point(E|C)` ⇒ `{A}` |
| 528 |
* `fork_point(E|B)` ⇒ `{B}` |
| 529 |
* `fork_point(E|A)` ⇒ `{A}` |
| 530 |
* `fork_point(D|C)` ⇒ `{C}` |
| 531 |
* `fork_point(D|B)` ⇒ `{B}` |
| 532 |
* `fork_point(B|C)` ⇒ `{A}` |
| 533 |
* `fork_point(A)` ⇒ `{A}` |
| 534 |
* `fork_point(none())` ⇒ `{}` |
| 535 |
|
| 536 |
## String patterns |
| 537 |
|
| 538 |
Functions that perform string matching support the following pattern syntax (the |
| 539 |
quotes are optional). |
| 540 |
|
| 541 |
By default, `"string"` is parsed as a `glob:` pattern. |
| 542 |
|
| 543 |
* `exact:"string"`: Matches strings exactly equal to `string`. |
| 544 |
* `glob:"pattern"`: Matches strings with Unix-style shell [wildcard |
| 545 |
`pattern`](https://docs.rs/globset/latest/globset/#syntax). |
| 546 |
* `regex:"pattern"`: Matches substrings with [regular |
| 547 |
expression `pattern`](https://docs.rs/regex/latest/regex/#syntax). |
| 548 |
* `substring:"string"`: Matches strings that contain `string`. |
| 549 |
|
| 550 |
You can append `-i` after the kind to match case‐insensitively (e.g. |
| 551 |
`glob-i:"fix*jpeg*"`). |
| 552 |
|
| 553 |
String patterns can be combined by using logical operators |
| 554 |
(e.g. `bookmarks(~glob:"ci/*")`): |
| 555 |
|
| 556 |
* `~x`: Matches everything but `x`. |
| 557 |
* `x & y`: Matches both `x` and `y`. |
| 558 |
* `x ~ y`: Matches `x` but not `y`. |
| 559 |
* `x | y`: Matches either `x` or `y` (or both). |
| 560 |
|
| 561 |
## Date patterns |
| 562 |
|
| 563 |
Functions that perform date matching support the following pattern syntax: |
| 564 |
|
| 565 |
* `after:"string"`: Matches dates exactly at or after the given date. |
| 566 |
* `before:"string"`: Matches dates before, but not including, the given date. |
| 567 |
|
| 568 |
Date strings can be specified in several forms, including: |
| 569 |
|
| 570 |
* 2024-02-01 |
| 571 |
* 2024-02-01T12:00:00 |
| 572 |
* 2024-02-01T12:00:00-08:00 |
| 573 |
* 2024-02-01 12:00:00 |
| 574 |
* 2 days ago |
| 575 |
* 5 minutes ago |
| 576 |
* yesterday |
| 577 |
* yesterday 5pm |
| 578 |
* yesterday 10:30 |
| 579 |
* yesterday 15:30 |
| 580 |
|
| 581 |
## Aliases |
| 582 |
|
| 583 |
New symbols, functions, and `<name>:<value>` patterns can be defined in the |
| 584 |
config file, by using any combination of the predefined symbols/functions and |
| 585 |
other aliases. |
| 586 |
|
| 587 |
Alias functions can be overloaded by the number of parameters. However, builtin |
| 588 |
function will be shadowed by name, and can't co-exist with aliases. |
| 589 |
|
| 590 |
For example: |
| 591 |
|
| 592 |
```toml |
| 593 |
[revset-aliases] |
| 594 |
HEAD = '@-' |
| 595 |
'user()' = 'user("[email protected]")' |
| 596 |
'user(x)' = 'author(x) | committer(x)' |
| 597 |
'grep:x' = 'description(regex:x)' |
| 598 |
``` |
| 599 |
|
| 600 |
### Alias descriptions |
| 601 |
|
| 602 |
Alias descriptions can be surfaced in shell completions by defining the alias |
| 603 |
as a table with `.doc` and `.definition` properties. For example: |
| 604 |
|
| 605 |
```toml |
| 606 |
[revset-aliases] |
| 607 |
HEAD = { definition = '@-', doc = 'The parent of the working-copy commit' } |
| 608 |
``` |
| 609 |
|
| 610 |
You can also use the dotted key syntax: |
| 611 |
|
| 612 |
```toml |
| 613 |
[revset-aliases] |
| 614 |
HEAD.definition = '@-' |
| 615 |
HEAD.doc = 'The parent of the working-copy commit' |
| 616 |
``` |
| 617 |
|
| 618 |
### Built-in Aliases |
| 619 |
|
| 620 |
The following aliases are built-in and used for certain operations. These functions |
| 621 |
are defined as aliases in order to allow you to overwrite them as needed. |
| 622 |
See [revsets.toml](https://github.com/jj-vcs/jj/blob/main/cli/src/config/revsets.toml) |
| 623 |
for a comprehensive list. |
| 624 |
|
| 625 |
* `trunk()`: Resolves to the head commit for the default bookmark of the default |
| 626 |
remote, or the remote named `upstream` or `origin`. This is set at the |
| 627 |
repository level upon initialization of a Jujutsu repository. |
| 628 |
|
| 629 |
If the default bookmark cannot be resolved during initialization, the default |
| 630 |
global configuration tries the bookmarks `main`, `master`, and `trunk` on the |
| 631 |
`upstream` and `origin` remotes. If more than one potential trunk commit |
| 632 |
exists, the newest one is chosen. If none of the bookmarks exist, the revset |
| 633 |
evaluates to `root()`. |
| 634 |
|
| 635 |
You can [override](./config.md) this as appropriate. If you do, make sure it |
| 636 |
always resolves to exactly one commit. For example: |
| 637 |
|
| 638 |
```toml |
| 639 |
[revset-aliases] |
| 640 |
'trunk()' = 'your-bookmark@your-remote' |
| 641 |
``` |
| 642 |
|
| 643 |
* `builtin_log()`: Resolves to `present(@) | |
| 644 |
ancestors(immutable_heads().., 2) | trunk()`. It is used as the default value |
| 645 |
for `revsets.log`, which is the set of revisions shown by `jj log` if no |
| 646 |
revisions or paths are specified. |
| 647 |
|
| 648 |
* `builtin_immutable_heads()`: Resolves to `trunk() | tags() | |
| 649 |
untracked_remote_bookmarks() | untracked_remote_tags()`. It is used as the |
| 650 |
default definition for `immutable_heads()` below. It is not recommended to |
| 651 |
redefine this alias. Prefer to redefine `immutable_heads()` instead. |
| 652 |
|
| 653 |
* `immutable_heads()`: The heads of the set of immutable commits (not "heads |
| 654 |
that are immutable"). Resolves to `trunk() | tags() | |
| 655 |
untracked_remote_bookmarks() | untracked_remote_tags()` by default. It is |
| 656 |
actually defined as `builtin_immutable_heads()`, and can be overridden as |
| 657 |
required. The full set of immutable commits is `::immutable_heads()` (i.e., |
| 658 |
`immutable()`). See [here](config.md#set-of-immutable-commits) for details. |
| 659 |
|
| 660 |
* `immutable()`: The set of commits that `jj` treats as immutable. This is |
| 661 |
equivalent to `::(immutable_heads() | root())`. It is not recommended to redefine |
| 662 |
this alias. Note that modifying this will *not* change whether a commit is immutable. |
| 663 |
To do that, edit `immutable_heads()`. |
| 664 |
|
| 665 |
* `mutable()`: The set of commits that `jj` treats as mutable. This is |
| 666 |
equivalent to `~immutable()`. It is not recommended to redefine this alias. |
| 667 |
Note that modifying this will *not* change whether a commit is immutable. |
| 668 |
To do that, edit `immutable_heads()`. |
| 669 |
|
| 670 |
* `visible()`: The set of visible commits. Resolves to `::visible_heads()`. |
| 671 |
This is equal to `all()` unless your revset includes |
| 672 |
[hidden revisions](#hidden-revisions). |
| 673 |
|
| 674 |
* `hidden()`: The set of hidden commits. Resolves to `~visible()`. This is empty |
| 675 |
unless your revset includes [hidden revisions](#hidden-revisions). Note that |
| 676 |
this is *not* [the set of all previously visible |
| 677 |
commits](https://github.com/jj-vcs/jj/issues/2623). |
| 678 |
|
| 679 |
## Examples |
| 680 |
|
| 681 |
Show the parent(s) of the working-copy commit (like `git log -1 HEAD`): |
| 682 |
|
| 683 |
```shell |
| 684 |
jj log -r @- |
| 685 |
``` |
| 686 |
|
| 687 |
Show all ancestors of the working copy (like plain `git log`) |
| 688 |
|
| 689 |
```shell |
| 690 |
jj log -r ::@ |
| 691 |
``` |
| 692 |
|
| 693 |
Show commits not on any remote bookmark: |
| 694 |
|
| 695 |
```shell |
| 696 |
jj log -r 'remote_bookmarks()..' |
| 697 |
``` |
| 698 |
|
| 699 |
Show commits not on `origin` (if you have other remotes like `fork`): |
| 700 |
|
| 701 |
```shell |
| 702 |
jj log -r 'remote_bookmarks(remote=origin)..' |
| 703 |
``` |
| 704 |
|
| 705 |
Show the initial commits in the repo (the ones Git calls "root commits"): |
| 706 |
|
| 707 |
```shell |
| 708 |
jj log -r 'root()+' |
| 709 |
``` |
| 710 |
|
| 711 |
Show some important commits (like `git log --simplify-by-decoration`): |
| 712 |
|
| 713 |
```shell |
| 714 |
jj log -r 'tags() | bookmarks()' |
| 715 |
``` |
| 716 |
|
| 717 |
Show local commits leading up to the working copy, as well as descendants of |
| 718 |
those commits: |
| 719 |
|
| 720 |
```shell |
| 721 |
jj log -r '(remote_bookmarks()..@)::' |
| 722 |
``` |
| 723 |
|
| 724 |
Show commits authored by "martinvonz" and containing the word "reset" in the |
| 725 |
description: |
| 726 |
|
| 727 |
```shell |
| 728 |
jj log -r 'author(*martinvonz*) & description(*reset*)' |
| 729 |
``` |