| 1 |
# Operation log |
| 2 |
|
| 3 |
## Introduction |
| 4 |
|
| 5 |
Jujutsu records each operation that modifies the repo in the "operation log". |
| 6 |
You can see the log with `jj op log`. Each operation object contains a snapshot |
| 7 |
of how the repo looked at the end of the operation. We call this snapshot a |
| 8 |
"view" object. The view contains information about where each bookmark, tag, and |
| 9 |
Git ref (in Git-backed repos) pointed, as well as the set of heads in the repo, |
| 10 |
and the current working-copy commit in each workspace. The operation object also |
| 11 |
(in addition to the view) contains pointers to the operation(s) immediately |
| 12 |
before it, as well as metadata about the operation, such as timestamps, |
| 13 |
username, hostname, description. |
| 14 |
|
| 15 |
The operation log allows you to undo operations one-by-one (`jj undo`) or even |
| 16 |
revert a specific one which isn't the most recent operation (`jj op revert`). It |
| 17 |
also lets you restore the entire repo to the way it looked at an earlier point |
| 18 |
(`jj op restore`). |
| 19 |
|
| 20 |
When referring to operations, you can use `@` to represent the current |
| 21 |
operation. |
| 22 |
|
| 23 |
The following operators are supported: |
| 24 |
|
| 25 |
* `x-`: Parents of `x` (e.g. `@-`) |
| 26 |
* `x+`: Children of `x` |
| 27 |
|
| 28 |
## Divergent operations |
| 29 |
|
| 30 |
One benefit of the operation log (and the reason for its creation) is that it |
| 31 |
allows lock-free concurrency -- you can run concurrent `jj` commands without |
| 32 |
corrupting the repo, even if you run the commands on different machines that |
| 33 |
access the repo via a distributed file system (as long as the file system |
| 34 |
guarantees that a write is only visible once previous writes are visible). When |
| 35 |
you run a `jj` command, it will start by loading the repo at the latest |
| 36 |
operation. It will not see any changes written by concurrent commands. If there |
| 37 |
are conflicts, you will be informed of them by subsequent `jj st` and/or |
| 38 |
`jj log` commands. |
| 39 |
|
| 40 |
As an example, let's say you had started editing the description of a change and |
| 41 |
then also update the contents of the change (maybe because you had forgotten the |
| 42 |
editor). When you eventually close your editor, the command will succeed and |
| 43 |
e.g. `jj log` will indicate that the change has diverged. |
| 44 |
|
| 45 |
## Loading an old version of the repo |
| 46 |
|
| 47 |
The top-level `--at-op`/`--at-operation` option allows you to load the repo at a |
| 48 |
specific operation. This can be useful for understanding how your repo got into |
| 49 |
the current state. It can be even more useful for understanding why someone |
| 50 |
else's repo got into its current state. |
| 51 |
|
| 52 |
When you use `--at-op`, the automatic snapshotting of the working copy will not |
| 53 |
take place. When referring to a revision with the `@` symbol (as many commands |
| 54 |
do by default), that will resolve to the working-copy commit recorded in the |
| 55 |
operation's view (which is actually how it always works -- it's just the |
| 56 |
snapshotting that's skipped with `--at-op`). |
| 57 |
|
| 58 |
As a top-level option, `--at-op` can be passed to any command. However, you |
| 59 |
will typically only want to run read-only commands. For example, `jj log`, |
| 60 |
`jj st`, and `jj diff` all make sense. It's still possible to run e.g. |
| 61 |
`jj --at-op=<some operation ID> describe`. That's equivalent to having started |
| 62 |
`jj describe` back when the specified operation was the most recent operation |
| 63 |
and then let it run until now (which can be done for that particular command by |
| 64 |
not closing the editor). There's practically no good reason to do that other |
| 65 |
than to simulate concurrent commands. |