2021-12-14 05:46:42 +00:00
|
|
|
# Revsets
|
|
|
|
|
|
|
|
Jujutsu supports a functional language for selecting a set of revisions.
|
|
|
|
Expressions in this language are called "revsets" (the idea comes from
|
|
|
|
[Mercurial](https://www.mercurial-scm.org/repo/hg/help/revsets)). The language
|
|
|
|
consists of symbols, operators, and functions.
|
|
|
|
|
|
|
|
Most `jj` commands accept a revset (or multiple). Many commands, such as
|
|
|
|
`jj diff -r <revset>` expect the revset to resolve to a single commit; it is
|
|
|
|
an error to pass a revset that resolves to more than one commit (or zero
|
|
|
|
commits) to such commands.
|
|
|
|
|
|
|
|
The words "revisions" and "commits" are used interchangeably in this document.
|
|
|
|
|
|
|
|
The commits listed by `jj log` without arguments are called "visible commits".
|
|
|
|
Other commits are only included if you explicitly mention them (e.g. by commit
|
|
|
|
ID or a Git ref pointing to them).
|
|
|
|
|
|
|
|
## Symbols
|
|
|
|
|
|
|
|
The symbol `root` refers to the virtual commit that is the oldest ancestor of
|
|
|
|
all other commits.
|
|
|
|
|
2022-08-25 23:37:09 +00:00
|
|
|
The symbol `@` refers to the working copy commit in the current workspace. Use
|
2022-08-25 23:34:18 +00:00
|
|
|
`<workspace name>@` to refer to the working-copy commit in another workspace.
|
2021-12-14 05:46:42 +00:00
|
|
|
|
|
|
|
A full commit ID refers to a single commit. A unique prefix of the full commit
|
|
|
|
ID can also be used. It is an error to use a non-unique prefix.
|
|
|
|
|
|
|
|
A full change ID refers to all visible commits with that change ID (there is
|
|
|
|
typically only one visible commit with a given change ID). A unique prefix of
|
|
|
|
the full change ID can also be used. It is an error to use a non-unique prefix.
|
|
|
|
|
|
|
|
Use double quotes to prevent a symbol from being interpreted as an expression.
|
2022-04-27 16:42:18 +00:00
|
|
|
For example, `"x-"` is the symbol `x-`, not the parents of symbol `x`.
|
2021-12-14 05:46:42 +00:00
|
|
|
Taking shell quoting into account, you may need to use something like
|
2022-04-27 16:42:18 +00:00
|
|
|
`jj log -r '"x-"'`.
|
2021-12-14 05:46:42 +00:00
|
|
|
|
|
|
|
### Priority
|
|
|
|
|
|
|
|
Jujutsu attempts to resolve a symbol in the following order:
|
|
|
|
|
|
|
|
1. `@`
|
|
|
|
2. `root`
|
|
|
|
3. Tag name
|
|
|
|
4. Branch name
|
|
|
|
5. Git ref
|
2022-11-27 09:39:35 +00:00
|
|
|
6. Commit ID or change ID
|
2021-12-14 05:46:42 +00:00
|
|
|
|
|
|
|
## Operators
|
|
|
|
|
|
|
|
The following operators are supported. `x` and `y` below can be any revset, not
|
|
|
|
only symbols.
|
|
|
|
|
|
|
|
* `x & y`: Revisions that are in both `x` and `y`.
|
|
|
|
* `x | y`: Revisions that are in either `x` or `y` (or both).
|
|
|
|
* `x ~ y`: Revisions that are in `x` but not in `y`.
|
2022-11-17 12:58:51 +00:00
|
|
|
* `~x`: Revisions that are not in `x`.
|
2021-12-14 05:46:42 +00:00
|
|
|
* `x-`: Parents of `x`.
|
|
|
|
* `x+`: Children of `x`.
|
|
|
|
* `:x`: Ancestors of `x`, including the commits in `x` itself.
|
|
|
|
* `x:`: Descendants of `x`, including the commits in `x` itself.
|
2023-05-05 17:29:56 +00:00
|
|
|
* `x:y`: Descendants of `x` that are also ancestors of `y`. Equivalent to
|
|
|
|
`x: & :y`. This is what `git log` calls `--ancestry-path x..y`.
|
|
|
|
* `x..y`: Ancestors of `y` that are not also ancestors of `x`. Equivalent to
|
|
|
|
`:y ~ :x`. This is what `git log` calls `x..y` (i.e. the same as we call it).
|
2021-12-16 05:57:55 +00:00
|
|
|
* `..x`: Ancestors of `x`, including the commits in `x` itself. Equivalent to
|
2023-06-14 10:55:36 +00:00
|
|
|
`:x` and provided for consistency.
|
2021-12-16 05:57:55 +00:00
|
|
|
* `x..`: Revisions that are not ancestors of `x`.
|
2021-12-14 05:46:42 +00:00
|
|
|
|
|
|
|
You can use parentheses to control evaluation order, such as `(x & y) | z` or
|
|
|
|
`x & (y | z)`.
|
|
|
|
|
|
|
|
## Functions
|
|
|
|
|
|
|
|
You can also specify revisions by using functions. Some functions take other
|
|
|
|
revsets (expressions) as arguments.
|
|
|
|
|
|
|
|
* `parents(x)`: Same as `x-`.
|
|
|
|
* `children(x)`: Same as `x+`.
|
|
|
|
* `ancestors(x)`: Same as `:x`.
|
|
|
|
* `descendants(x)`: Same as `x:`.
|
2023-01-13 22:17:33 +00:00
|
|
|
* `connected(x)`: Same as `x:x`. Useful when `x` includes several commits.
|
2021-12-14 05:46:42 +00:00
|
|
|
* `all()`: All visible commits in the repo.
|
|
|
|
* `none()`: No commits. This function is rarely useful; it is provided for
|
|
|
|
completeness.
|
2023-01-12 10:01:35 +00:00
|
|
|
* `branches([needle])`: All local branch targets. If `needle` is specified,
|
|
|
|
branches whose name contains the given string are selected. For example,
|
|
|
|
`branches(push)` would match the branches `push-123` and `repushed` but not
|
|
|
|
the branch `main`. If a branch is in a conflicted state, all its possible
|
|
|
|
targets are included.
|
2023-02-08 09:55:15 +00:00
|
|
|
* `remote_branches([branch_needle[, [remote=]remote_needle]])`: All remote
|
|
|
|
branch targets across all remotes. If just the `branch_needle` is specified,
|
2023-01-12 10:01:35 +00:00
|
|
|
branches whose name contains the given string across all remotes are
|
|
|
|
selected. If both `branch_needle` and `remote_needle` are specified, the
|
|
|
|
selection is further restricted to just the remotes whose name contains
|
|
|
|
`remote_needle`. For example, `remote_branches(push, ri)` would match the
|
|
|
|
branches `push-123@origin` and `repushed@private` but not `push-123@upstream`
|
|
|
|
or `main@origin` or `main@upstream`. If a branch is in a conflicted state,
|
2021-12-14 05:46:42 +00:00
|
|
|
all its possible targets are included.
|
|
|
|
* `tags()`: All tag targets. If a tag is in a conflicted state, all its
|
|
|
|
possible targets are included.
|
|
|
|
* `git_refs()`: All Git ref targets as of the last import. If a Git ref
|
|
|
|
is in a conflicted state, all its possible targets are included.
|
|
|
|
* `git_head()`: The Git `HEAD` target as of the last import.
|
2023-03-28 06:13:31 +00:00
|
|
|
* `visible_heads()`: All visible heads (same as `heads(all())`).
|
|
|
|
* `heads(x)`: Commits in `x` that are not ancestors of other commits in `x`.
|
2023-06-14 10:55:36 +00:00
|
|
|
Note that this is different from
|
|
|
|
[Mercurial's](https://repo.mercurial-scm.org/hg/help/revsets) `heads(x)`
|
|
|
|
function, which is equivalent to `x ~ x-`.
|
2022-04-13 20:55:47 +00:00
|
|
|
* `roots(x)`: Commits in `x` that are not descendants of other commits in `x`.
|
2023-06-14 10:55:36 +00:00
|
|
|
Note that this is different from
|
|
|
|
[Mercurial's](https://repo.mercurial-scm.org/hg/help/revsets) `roots(x)`
|
|
|
|
function, which is equivalent to `x ~ x+`.
|
2023-03-25 03:14:26 +00:00
|
|
|
* `latest(x[, count])`: Latest `count` commits in `x`, based on committer
|
|
|
|
timestamp. The default `count` is 1.
|
2022-10-25 13:20:59 +00:00
|
|
|
* `merges()`: Merge commits.
|
2022-10-25 13:08:11 +00:00
|
|
|
* `description(needle)`: Commits with the given string in their
|
|
|
|
description.
|
|
|
|
* `author(needle)`: Commits with the given string in the author's name or
|
|
|
|
email.
|
|
|
|
* `committer(needle)`: Commits with the given string in the committer's
|
|
|
|
name or email.
|
2022-11-15 08:12:37 +00:00
|
|
|
* `empty()`: Commits modifying no files. This also includes `merges()` without
|
|
|
|
user modifications and `root`.
|
2022-11-01 08:11:22 +00:00
|
|
|
* `file(pattern..)`: Commits modifying the paths specified by the `pattern..`.
|
2023-04-25 17:25:46 +00:00
|
|
|
Paths are relative to the directory `jj` was invoked from. A directory name
|
|
|
|
will match all files in that directory and its subdirectories. For example,
|
|
|
|
`file(foo)` will match files `foo`, `foo/bar`, `foo/bar/baz`, but not file
|
|
|
|
`foobar`.
|
2023-04-05 03:05:51 +00:00
|
|
|
* `conflict()`: Commits with conflicts.
|
2022-11-07 07:29:35 +00:00
|
|
|
* `present(x)`: Same as `x`, but evaluated to `none()` if any of the commits
|
|
|
|
in `x` doesn't exist (e.g. is an unknown branch name.)
|
2021-12-14 05:46:42 +00:00
|
|
|
|
2022-11-25 10:27:13 +00:00
|
|
|
## Aliases
|
|
|
|
|
2022-11-26 11:41:55 +00:00
|
|
|
New symbols and functions can be defined in the config file, by using any
|
|
|
|
combination of the predefined symbols/functions and other aliases.
|
2022-11-25 10:27:13 +00:00
|
|
|
|
|
|
|
For example:
|
2023-01-12 10:01:35 +00:00
|
|
|
|
2022-11-25 10:27:13 +00:00
|
|
|
```toml
|
|
|
|
[revset-aliases]
|
|
|
|
'mine' = 'author(martinvonz)'
|
2022-11-26 11:41:55 +00:00
|
|
|
'user(x)' = 'author(x) | committer(x)'
|
2022-11-25 10:27:13 +00:00
|
|
|
```
|
|
|
|
|
2021-12-14 05:46:42 +00:00
|
|
|
## Examples
|
|
|
|
|
2022-08-25 23:34:18 +00:00
|
|
|
Show the parent(s) of the working-copy commit (like `git log -1 HEAD`):
|
2023-01-12 10:01:35 +00:00
|
|
|
|
2021-12-14 05:46:42 +00:00
|
|
|
```
|
|
|
|
jj log -r @-
|
|
|
|
```
|
|
|
|
|
|
|
|
Show commits not on any remote branch:
|
2023-01-12 10:01:35 +00:00
|
|
|
|
2021-12-14 05:46:42 +00:00
|
|
|
```
|
2021-12-16 05:57:55 +00:00
|
|
|
jj log -r 'remote_branches()..'
|
2021-12-14 05:46:42 +00:00
|
|
|
```
|
|
|
|
|
2023-01-12 10:01:35 +00:00
|
|
|
Show commits not on `origin` (if you have other remotes like `fork`):
|
|
|
|
|
|
|
|
```
|
2023-02-08 09:55:15 +00:00
|
|
|
jj log -r 'remote_branches(remote=origin)..'
|
2023-01-12 10:01:35 +00:00
|
|
|
```
|
|
|
|
|
2021-12-14 05:46:42 +00:00
|
|
|
Show all ancestors of the working copy (almost like plain `git log`)
|
2023-01-12 10:01:35 +00:00
|
|
|
|
2021-12-14 05:46:42 +00:00
|
|
|
```
|
|
|
|
jj log -r :@
|
|
|
|
```
|
|
|
|
|
|
|
|
Show the initial commits in the repo (the ones Git calls "root commits"):
|
2023-01-12 10:01:35 +00:00
|
|
|
|
2021-12-14 05:46:42 +00:00
|
|
|
```
|
|
|
|
jj log -r root+
|
|
|
|
```
|
|
|
|
|
|
|
|
Show some important commits (like `git --simplify-by-decoration`):
|
2023-01-12 10:01:35 +00:00
|
|
|
|
2021-12-14 05:46:42 +00:00
|
|
|
```
|
|
|
|
jj log -r 'tags() | branches()'
|
|
|
|
```
|
|
|
|
|
|
|
|
Show local commits leading up to the working copy, as well as descendants of
|
|
|
|
those commits:
|
2023-01-12 10:01:35 +00:00
|
|
|
|
2021-12-14 05:46:42 +00:00
|
|
|
```
|
|
|
|
jj log -r '(remote_branches()..@):'
|
|
|
|
```
|
2021-12-16 06:16:22 +00:00
|
|
|
|
|
|
|
Show commits authored by "martinvonz" and containing the word "reset" in the
|
|
|
|
description:
|
2023-01-12 10:01:35 +00:00
|
|
|
|
2021-12-16 06:16:22 +00:00
|
|
|
```
|
|
|
|
jj log -r 'author(martinvonz) & description(reset)'
|
|
|
|
```
|