Because the use of the change id is recommended, any operation should abort if a valid change id happens to match a commit id. We still try the commit id lookup first as the change id lookup is more costly. Ambiguous change/commit id is reported as AmbiguousCommitIdPrefix for now. Maybe we can merge AmbiguousCommit/ChangeIdPrefix errors into one? Closes #799
5.6 KiB
Revsets
Jujutsu supports a functional language for selecting a set of revisions. Expressions in this language are called "revsets" (the idea comes from Mercurial). 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.
The symbol @
refers to the working copy commit in the current workspace. Use
<workspace name>@
to refer to the working-copy commit in another workspace.
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.
For example, "x-"
is the symbol x-
, not the parents of symbol x
.
Taking shell quoting into account, you may need to use something like
jj log -r '"x-"'
.
Priority
Jujutsu attempts to resolve a symbol in the following order:
@
root
- Tag name
- Branch name
- Git ref
- Commit ID or change ID
Operators
The following operators are supported. x
and y
below can be any revset, not
only symbols.
x & y
: Revisions that are in bothx
andy
.x | y
: Revisions that are in eitherx
ory
(or both).x ~ y
: Revisions that are inx
but not iny
.x-
: Parents ofx
.x+
: Children ofx
.:x
: Ancestors ofx
, including the commits inx
itself.x:
: Descendants ofx
, including the commits inx
itself.x:y
: Descendants ofx
that are also ancestors ofy
, both inclusive. Equivalent tox: & :y
. This is whatgit log
calls--ancestry-path x..y
.x..y
: Ancestors ofy
that are not also ancestors ofx
, both inclusive. Equivalent to:y ~ :x
. This is whatgit log
callsx..y
(i.e. the same as we call it)...x
: Ancestors ofx
, including the commits inx
itself. Equivalent to:x
and provided for consistency.x..
: Revisions that are not ancestors ofx
.
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 asx-
.children(x)
: Same asx+
.ancestors(x)
: Same as:x
.descendants(x)
: Same asx:
.connected(x)
: Same asx:x
.all()
: All visible commits in the repo.none()
: No commits. This function is rarely useful; it is provided for completeness.branches()
: All local branch targets. If a branch is in a conflicted state, all its possible targets are included.remote_branches()
: All remote branch targets across all remotes. If a branch is in a conflicted state, 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 GitHEAD
target as of the last import.heads([x])
: Commits inx
that are not ancestors of other commits inx
. Ifx
was not specified, it selects all visible heads (as if you had saidheads(all())
).roots(x)
: Commits inx
that are not descendants of other commits inx
.merges()
: Merge commits.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.empty()
: Commits modifying no files. This also includesmerges()
without user modifications androot
.file(pattern..)
: Commits modifying the paths specified by thepattern..
.present(x)
: Same asx
, but evaluated tonone()
if any of the commits inx
doesn't exist (e.g. is an unknown branch name.)
Aliases
New symbols can be defined in the config file, by using any combination of the predefined symbols/functions and other aliases.
For example:
[revset-aliases]
'mine' = 'author(martinvonz)'
Examples
Show the parent(s) of the working-copy commit (like git log -1 HEAD
):
jj log -r @-
Show commits not on any remote branch:
jj log -r 'remote_branches()..'
Show all ancestors of the working copy (almost like plain git log
)
jj log -r :@
Show the initial commits in the repo (the ones Git calls "root commits"):
jj log -r root+
Show some important commits (like git --simplify-by-decoration
):
jj log -r 'tags() | branches()'
Show local commits leading up to the working copy, as well as descendants of those commits:
jj log -r '(remote_branches()..@):'
Show commits authored by "martinvonz" and containing the word "reset" in the description:
jj log -r 'author(martinvonz) & description(reset)'