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.
|
|
|
|
|
2023-11-01 02:41:03 +00:00
|
|
|
Most revsets search only the [visible commits](glossary.md#visible-commits).
|
2021-12-14 05:46:42 +00:00
|
|
|
Other commits are only included if you explicitly mention them (e.g. by commit
|
|
|
|
ID or a Git ref pointing to them).
|
|
|
|
|
|
|
|
## Symbols
|
|
|
|
|
2023-09-03 04:41:15 +00:00
|
|
|
The `@` expression refers to the working copy commit in the current workspace.
|
|
|
|
Use `<workspace name>@` to refer to the working-copy commit in another
|
|
|
|
workspace. Use `<name>@<remote>` to refer to a remote-tracking branch.
|
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:
|
|
|
|
|
2023-09-03 03:47:23 +00:00
|
|
|
1. Tag name
|
|
|
|
2. Branch name
|
|
|
|
3. Git ref
|
|
|
|
4. 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`.
|
2023-09-05 21:58:13 +00:00
|
|
|
* `::x`: Ancestors of `x`, including the commits in `x` itself.
|
|
|
|
* `x::`: Descendants of `x`, including the commits in `x` itself.
|
|
|
|
* `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`.
|
2023-09-03 08:08:16 +00:00
|
|
|
* `::`: All visible commits in the repo. Equivalent to `all()`.
|
2023-09-05 21:58:13 +00:00
|
|
|
* `:x`, `x:`, and `x:y`: Deprecated versions of `::x`, `x::`, and `x::y` We
|
|
|
|
plan to delete them in jj 0.15+.
|
2023-05-05 17:29:56 +00:00
|
|
|
* `x..y`: Ancestors of `y` that are not also ancestors of `x`. Equivalent to
|
2023-09-05 21:58:13 +00:00
|
|
|
`::y ~ ::x`. This is what `git log` calls `x..y` (i.e. the same as we call it).
|
2023-09-04 23:38:28 +00:00
|
|
|
* `..x`: Ancestors of `x`, including the commits in `x` itself, but excluding
|
2023-09-05 21:58:13 +00:00
|
|
|
the root commit. Equivalent to `::x ~ root()`.
|
2021-12-16 05:57:55 +00:00
|
|
|
* `x..`: Revisions that are not ancestors of `x`.
|
2023-09-03 08:08:16 +00:00
|
|
|
* `..`: All visible commits in the repo, but excluding the root commit.
|
|
|
|
Equivalent to `~root()`.
|
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+`.
|
2023-09-02 06:02:35 +00:00
|
|
|
* `ancestors(x[, depth])`: `ancestors(x)` is the same as `::x`.
|
|
|
|
`ancestors(x, depth)` returns the ancestors of `x` limited to the given
|
|
|
|
`depth`.
|
2023-09-05 21:58:13 +00:00
|
|
|
* `descendants(x)`: Same as `x::`.
|
|
|
|
* `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-08-16 02:35:43 +00:00
|
|
|
* `branches([pattern])`: All local branch targets. If `pattern` is specified,
|
2023-10-31 19:30:19 +00:00
|
|
|
this selects the branches whose name match the given [string
|
|
|
|
pattern](#string-patterns). 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.
|
|
|
|
|
|
|
|
* `remote_branches([branch_pattern[, [remote=]remote_pattern]])`: All remote
|
|
|
|
branch targets across all remotes. If just the `branch_pattern` is
|
|
|
|
specified, the branches whose names match the given [string
|
|
|
|
pattern](#string-patterns) across all remotes are selected. If both
|
|
|
|
`branch_pattern` and `remote_pattern` are specified, the selection is
|
|
|
|
further restricted to just the remotes whose names match `remote_pattern`.
|
|
|
|
|
|
|
|
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, all
|
|
|
|
its possible targets are included.
|
|
|
|
|
2021-12-14 05:46:42 +00:00
|
|
|
* `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.
|
2023-07-11 04:44:17 +00:00
|
|
|
* `git_head()`: The Git `HEAD` target as of the last import. Equivalent to
|
|
|
|
`present(HEAD@git)`.
|
2023-03-28 06:13:31 +00:00
|
|
|
* `visible_heads()`: All visible heads (same as `heads(all())`).
|
2023-09-03 03:47:23 +00:00
|
|
|
* `root()`: The virtual commit that is the oldest ancestor of all other commits.
|
2023-03-28 06:13:31 +00:00
|
|
|
* `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.
|
2023-10-31 19:30:19 +00:00
|
|
|
* `description(pattern)`: Commits that have a description matching the given
|
|
|
|
[string pattern](#string-patterns).
|
|
|
|
* `author(pattern)`: Commits with the author's name or email matching the given
|
|
|
|
[string pattern](#string-patterns).
|
2023-08-14 00:35:11 +00:00
|
|
|
* `mine()`: Commits where the author's email matches the email of the current
|
|
|
|
user.
|
2023-10-31 19:30:19 +00:00
|
|
|
* `committer(pattern)`: Commits with the committer's name or email matching the
|
|
|
|
given [string pattern](#string-patterns).
|
2022-11-15 08:12:37 +00:00
|
|
|
* `empty()`: Commits modifying no files. This also includes `merges()` without
|
2023-09-03 03:47:23 +00:00
|
|
|
user modifications and `root()`.
|
2023-10-31 19:30:19 +00:00
|
|
|
|
|
|
|
* `file(relativepath)` or `file("relativepath"[, "relativepath"]...)`: Commits
|
|
|
|
modifying one of the paths specified. Currently, string patterns are *not*
|
|
|
|
supported in the path arguments.
|
|
|
|
|
|
|
|
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`.
|
|
|
|
It will *not* match `foobar` or `bar/foo`.
|
|
|
|
|
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
|
|
|
|
2023-08-16 09:41:21 +00:00
|
|
|
## String patterns
|
|
|
|
|
2023-10-31 19:30:19 +00:00
|
|
|
Functions that perform string matching support the following pattern syntax:
|
2023-08-16 09:41:21 +00:00
|
|
|
|
2023-10-31 19:30:19 +00:00
|
|
|
* `"string"`, or `string` (the quotes are optional), or `substring:"string"`:
|
|
|
|
Matches strings that contain `string`.
|
2023-08-19 00:59:40 +00:00
|
|
|
* `exact:"string"`: Matches strings exactly equal to `string`.
|
2023-10-31 19:30:19 +00:00
|
|
|
* `glob:"pattern"`: Matches strings with Unix-style shell [wildcard
|
|
|
|
`pattern`](https://docs.rs/glob/latest/glob/struct.Pattern.html).
|
2023-08-16 09:41:21 +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
|
|
|
```
|
|
|
|
|
2023-08-15 21:49:11 +00:00
|
|
|
### Built-in Aliases
|
|
|
|
|
|
|
|
The following aliases are built-in and used for certain operations. These functions
|
|
|
|
are defined as aliases in order to allow you to overwrite them as needed.
|
|
|
|
See [revsets.toml](https://github.com/martinvonz/jj/blob/main/cli/src/config/revsets.toml)
|
|
|
|
for a comprehensive list.
|
|
|
|
|
2023-09-20 02:20:30 +00:00
|
|
|
* `trunk()`: Resolves to the head commit for the trunk branch of the remote
|
|
|
|
named `origin` or `upstream`. The branches `main`, `master`, and `trunk` are
|
|
|
|
tried. If more than one potential trunk commit exists, the newest one is
|
|
|
|
chosen. If none of the branches exist, the revset evaluates to `root()`.
|
2023-08-15 21:49:11 +00:00
|
|
|
|
|
|
|
You can [override](./config.md) this as appropriate. If you do, make sure it
|
|
|
|
always resolves to exactly one commit. For example:
|
|
|
|
|
|
|
|
```toml
|
|
|
|
[revset-aliases]
|
2023-09-19 12:09:25 +00:00
|
|
|
'trunk()' = 'your-branch@your-remote'
|
2023-08-15 21:49:11 +00:00
|
|
|
```
|
|
|
|
|
2023-10-23 05:36:36 +00:00
|
|
|
* `immutable_heads()`: Resolves to `trunk() | tags()` by default. See
|
|
|
|
[here](config.md#set-of-immutable-commits) for details.
|
|
|
|
|
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
|
|
|
```
|
2023-09-05 21:58:13 +00:00
|
|
|
jj log -r ::@
|
2021-12-14 05:46:42 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
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
|
|
|
```
|
2023-09-03 03:47:23 +00:00
|
|
|
jj log -r root()+
|
2021-12-14 05:46:42 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
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
|
|
|
|
revsets: allow `::` as synonym for `:`
The `--allow-large-revsets` flag we have on `jj rebase` and `jj new`
allows the user to do e.g. `jj rebase --allow-large-revsets -b
main.. -d main` to rebase all commits that are not in main onto
main. The reason we don't allow these revsets to resolve to multiple
commits by default is that we think users might specify multiple
commits by mistake. That's probably not much of a problem with `jj
rebase -b` (maybe we should always allow that to resolve to multiple
commits), but the user might want to know if `jj rebase -d @-`
resolves to multiple commits.
One problem with having a flag to allow multiple commits is that it
needs to be added to every command where we want to allow multiple
commits but default to one. Also, it should probably apply to each
revset argument those commands take. For example, even if the user
meant `-b main..` to resolve to multiple commits, they might not have
meant `-d main` to resolve to multiple commits (which it will in case
of a conflicted branch), so we might want separate
`--allow-large-revsets-in-destination` and
`--allow-large-revsets-in-source`, which gets quite cumbersome. It
seems better to have some syntax in the individual revsets for saying
that multiple commits are allowed.
One proposal I had was to use a `multiple()` revset function which
would have no effect in general but would be used as a marker if used
at the top level (e.g. `jj rebase -d 'multiple(@-)'`). After some
discussion on the PR adding that function (#1911), it seems that the
consensus is to instead use a prefix like `many:` or `all:`. That
avoids the problem with having a function that has no effect unless
it's used at the top level (`jj rebase -d 'multiple(x)|y'` would have
no effect).
Since we already have the `:` operator for DAG ranges, we need to
change it to make room for `many:`/`all:` syntax. This commit starts
that by allowing both `:` and `::`.
I have tried to update the documentation in this commit to either
mention both forms, or just the new and preferred `::` form. However,
it's useless to search for `:` in Rust code, so I'm sure I've missed
many instances. We'll have to address those as we notice them. I'll
let most tests use `:` until we deprecate it or delete it.
2023-07-27 23:27:44 +00:00
|
|
|
|
2021-12-14 05:46:42 +00:00
|
|
|
```
|
2023-09-05 21:58:13 +00:00
|
|
|
jj log -r '(remote_branches()..@)::'
|
2021-12-14 05:46:42 +00:00
|
|
|
```
|
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)'
|
|
|
|
```
|