|
| 1 | +# 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 commit | |
| 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 | +| `--destination` | `-d` | Commits become descendants of the destination. | |
| 25 | +| `--insert-after` | `-A` | Insert commits _between_ the specified revisions and their children. | |
| 26 | +| `--insert-before` | `-B` | Insert commits _between_ the specified revisions and their parents. | |
| 27 | +| `--to`, `--into` | `-t` | Which commit to place the selected _contents_. | |
| 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 commits around also need to specify the destinations. |
| 49 | + |
| 50 | +- `--destination REV` (`-d REV`) places commits as children of `REV`. |
| 51 | +- `--insert-after REV` (`-A REV`) inserts commits as children of `REV` and parents of `REV+`. |
| 52 | +- `--insert-before REV` (`-B REV`) inserts commits as the children of `REV-` and parents of `REV`. |
| 53 | + |
| 54 | +Examples: |
| 55 | + |
| 56 | +- `jj rebase -r REV -d main` rebases revisions in `REV` as children of `main`. |
| 57 | +- `jj rebase -r REV -B B` inserts revisions `REV` between `B` and its parents. |
| 58 | +- `jj rebase -r REV -A main -B B` inserts revisions `REV` between `main` and `B`. |
| 59 | +- `jj revert -r xyz -d main` creates the commit that reverts `xyz` then rebases it on top of `main`. |
| 60 | + |
| 61 | +## Manipulating diffs and snapshots |
| 62 | + |
| 63 | +Commands that view or manipulate the _contents_ of commits use `--from` and `--to`. |
| 64 | + |
| 65 | +- `--from` (`-f`) specifies the revision that provides the contents (the "from" |
| 66 | + snapshot). |
| 67 | + |
| 68 | +- `--to` or `--into` (`-t`) specifies which revisions the contents will be moved |
| 69 | + or copied to. |
| 70 | + |
| 71 | +Examples: |
| 72 | + |
| 73 | +- `jj diff --from F --to T` compares the files at revision `F` to the files at |
| 74 | + revision `T`. |
| 75 | + |
| 76 | +- `jj restore --from F --to T` copies file contents from `F` to `T`. |
| 77 | + |
| 78 | +- `jj squash --from F --into T` moves the file changes from `F` to `T`. |
| 79 | + |
| 80 | +!!! info |
| 81 | + |
| 82 | + `--into` and `--to` are synonyms. Commands that accept one also accept the |
| 83 | + other. They both exist because it makes commands read more clearly in |
| 84 | + English. |
| 85 | + |
| 86 | +### Special cases that use `-r` |
| 87 | + |
| 88 | +Some commands manipulate revision contents but allow for `-r`. This means |
| 89 | +"compared with its parent". For example, `jj diff -r R` means "compare revision |
| 90 | +`R` to its parent `R-`". |
| 91 | + |
| 92 | +## Other special cases |
| 93 | + |
| 94 | +`jj git push --change REV` (`-c REV`) means (a) create a new bookmark with a |
| 95 | +generated name, and (b) immediately push it to the remote. |
| 96 | + |
| 97 | +`jj restore --changes-in REV` (`-c REV`) means, "remove any changes to the given |
| 98 | +files in `REV`". This doesn't use `-r` because `jj restore -r REV` might seem |
| 99 | +like it would restore files _from_ `REV` into the working copy. |
| 100 | + |
| 101 | +`jj rebase --branch REV` (`-b REV`) rebases a topological branch of revisions |
| 102 | +with respect to some base. This is a convenience for a very common operation. |
| 103 | +These commands are equivalent: |
| 104 | + |
| 105 | +- `jj rebase -d main -b @` |
| 106 | +- `jj rebase -d main -r (main..@)::` |
| 107 | +- `jj rebase -d main -s roots(main..@)` |
| 108 | +- `jj rebase -d main` (this is so common that `-b @` is the default "source" of |
| 109 | + a rebase if unspecified) |
0 commit comments