Debian Codegraph @

cli/docs/guides/cli-revision-options.md

raw
1 # CLI options for specifying revisions
2
3 Jujutsu has several CLI options for selecting revisions. They are used
4 consistently, but it can be difficult to remember when each one is used.
5
6 This document explains the difference between each option.
7
8 ## Summary
9
10 These flags are used to specify the sources of the operation:
11
12 | Long flag | Short flag | Description |
13 | ------------------------------- | ---------- | ------------------------------------------------------------------------------- |
14 | `--revision` (or `--revisions`) | `-r` | The default, especially for commands that don't need to specify a destination. |
15 | `--source` | `-s` | The specified revision and all its descendants. |
16 | `--from` | `-f` | The _contents_ of a revision, or the bookmarks on a revision. |
17 | `--branch` | `-b` | A whole branch, relative to the destination. |
18
19 These flags are used when commands need both a "source" revision and a
20 "destination" revision:
21
22 | Long flag | Short flag | Description |
23 | ----------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------- |
24 | `--onto` | `-o` | Create children of the specified revisions. |
25 | `--insert-after` | `-A` | Insert _between_ the specified revisions and their children. |
26 | `--insert-before` | `-B` | Insert _between_ the specified revisions and their parents. |
27 | `--to`, `--into` | `-t` | Which revision to place the selected _contents_ into, or move the bookmarks to, or compare the `from` revision contents against. |
28
29 ## Manipulating revisions
30
31 Most commands accept a revset with `-r`. This selects the revisions in the
32 revset, and no more. Examples: `jj log -r REV` displays revisions in `REV`, `jj
33 split -r REV` splits revision `REV` into multiple revisions.
34
35 `--source` (`-s`) is used with commands that manipulate revisions _and their
36 descendants_. `-s REV` is essentially identical to `-r REV::`.
37
38 Examples of `-r` and `-s`:
39
40 - `jj log -r xyz` displays revision `xyz`.
41
42 - `jj fix -s xyz` runs fix tools on files in `xyz` and all of its descendants.
43 This command _must_ operate on all of a revision's descendants, so it accepts
44 `-s` and not `-r` to communicate this fact.
45
46 ### Specifying destinations
47
48 Commands that move revisions around also need to specify the destinations.
49
50 - `--onto REV` (`-o REV`) places revisions as children of `REV`.
51 - `--insert-after REV` (`-A REV`) inserts revisions as children of `REV` and parents of `REV+`.
52 - `--insert-before REV` (`-B REV`) inserts revisions as the children of `REV-` and parents of `REV`.
53
54 Examples:
55
56 - `jj rebase -r REV -o main` rebases revisions in `REV` as children of `main`.
57 - `jj rebase -r REV -B yyy` inserts revisions `REV` between `yyy` and its parents.
58 - `jj rebase -r REV -A main -B yyy` inserts revisions `REV` between `main` and `yyy`.
59 - `jj revert -r xyz -o main` creates a revision that reverts `xyz` then rebases it on top of `main`.
60
61 ## Manipulating diffs and file contents
62
63 Commands that view or manipulate the _contents_ of revisions use `--from` and
64 `--to` (or `--into`).
65
66 Examples:
67
68 - `jj diff --from F --to T` compares the files at revision `F` to the files at
69 revision `T`.
70
71 - `jj restore --from F --to T` copies file contents from `F` to `T`.
72
73 - `jj squash --from F --into T` moves the file changes from `F` to `T`.
74
75 !!! info
76
77 Commands that accept `--into` also accept `--to`. You can always use `--to`
78 if you're not sure which to use.
79
80 They both exist because "into" makes some commands read more clearly in
81 English. For example, `jj squash --from X --into Y`.
82
83 ### Special cases that use `-r`
84
85 Some commands manipulate revision contents but allow for `-r`. This means
86 "compared with its parent". For example, `jj diff -r R` means "compare revision
87 `R` to its parent `R-`".
88
89 ### Special cases that don't use any option
90
91 Most commands accept revisions as options and paths as positional parameters.
92 For example, the command to display the diff of a specific file in a specific
93 revision is:
94
95 ```command
96 $ jj diff -r REV file.txt
97 ```
98
99 However, some commands cannot accept paths, so they allow omitting the `-r`
100 flag. For example, the canonical command would be `jj new -r xyz`, but this
101 command is so common that Jujutsu allows `jj new xyz`.
102
103 The commands that allow omitting the `-r` are:
104
105 - `jj abandon`
106 - `jj describe`
107 - `jj duplicate`
108 - `jj metaedit`
109 - `jj new`
110 - `jj parallelize`
111 - `jj show`
112
113 ## Other special cases
114
115 `jj git push --change REV` (`-c REV`) means (a) create a new bookmark with a
116 generated name, and (b) immediately push it to the remote.
117
118 `jj restore --changes-in REV` (`-c REV`) means, "remove any changes to the given
119 files in `REV`". This doesn't use `-r` because `jj restore -r REV` might seem
120 like it would restore files _from_ `REV` into the working copy.
121
122 `jj rebase --branch REV` (`-b REV`) rebases a topological branch of revisions
123 with respect to some base. This is a convenience for a very common operation.
124 These commands are equivalent:
125
126 - `jj rebase -o main -b @`
127 - `jj rebase -o main -r (main..@)::`
128 - `jj rebase -o main -s roots(main..@)`
129 - `jj rebase -o main` (this is so common that `-b @` is the default "source" of
130 a rebase if unspecified)