| 1 |
# Frequently asked questions |
| 2 |
|
| 3 |
### Why does my bookmark not move to the new commit after `jj new/commit`? |
| 4 |
|
| 5 |
If you're familiar with Git, you might expect the current bookmark to move forward |
| 6 |
when you commit. However, Jujutsu does not have a concept of a "current bookmark". |
| 7 |
|
| 8 |
To move bookmarks, use `jj bookmark move`. |
| 9 |
|
| 10 |
### I made a commit and `jj git push --all` says "Nothing changed" instead of pushing it. What do I do? |
| 11 |
|
| 12 |
`jj git push --all` pushes all _bookmarks_, not all revisions. You have two |
| 13 |
options: |
| 14 |
|
| 15 |
* Using `jj git push --change` will automatically create a bookmark and push it. |
| 16 |
* Using `jj bookmark` commands to create or move a bookmark to either the commit |
| 17 |
you want to push or a descendant of it. Unlike Git, Jujutsu doesn't do this |
| 18 |
automatically (see previous question). |
| 19 |
|
| 20 |
### Where is my commit, why is it not visible in `jj log`? |
| 21 |
|
| 22 |
Is your commit visible with `jj log -r 'all()'`? |
| 23 |
|
| 24 |
If yes, you should be aware that `jj log` only shows a subset of the commits in |
| 25 |
the repo by default. Most commits that exist on a remote are not shown. Local |
| 26 |
commits and their immediate parents (for context) are shown. The thinking is |
| 27 |
that you are more likely to interact with this set of commits. You can configure |
| 28 |
the set of revisions to show by default by overriding `revsets.log` as described |
| 29 |
in [config]. |
| 30 |
|
| 31 |
If not, the revision may have been abandoned (e.g. because you |
| 32 |
used `jj abandon`, or because it's an obsolete version that's been rewritten |
| 33 |
with `jj rebase`, `jj describe`, etc). In that case, `jj log -r commit_id` |
| 34 |
should show the revision as "hidden". `jj new commit_id` should make the |
| 35 |
revision visible again. |
| 36 |
|
| 37 |
See [revsets] and [templates] for further guidance. |
| 38 |
|
| 39 |
### What are elided revisions in the output of `jj log`? How can I display them? |
| 40 |
|
| 41 |
"Elided revisions" appears in the log when one revision descends from another, |
| 42 |
both are in the revset, but the revisions connecting them are _not_ in the |
| 43 |
revset. |
| 44 |
|
| 45 |
For example, suppose you log the revset `tyl|mus` which contains exactly two |
| 46 |
revisions: |
| 47 |
|
| 48 |
```sh |
| 49 |
$ jj log -r 'tyl|mus' |
| 50 |
○ musnqzvt [email protected] 1 minute ago 9a09f8a5 |
| 51 |
│ Revision C |
| 52 |
~ (elided revisions) |
| 53 |
○ tylynnzk [email protected] 1 minute ago f26967c8 |
| 54 |
│ Revision A |
| 55 |
``` |
| 56 |
|
| 57 |
Only the two revisions in the revset are displayed. The text "(elided |
| 58 |
revisions)" is shown to indicate that `musnqzvt` descends from `tylynnzk`, but |
| 59 |
the nodes connecting them are not in the revset. |
| 60 |
|
| 61 |
To view the elided revisions, change the [revset expression](revsets.md) so it |
| 62 |
includes the connecting revisions. The `connected()` revset function does |
| 63 |
exactly this: |
| 64 |
|
| 65 |
```sh |
| 66 |
$ jj log -r 'connected(tyl|mus)' |
| 67 |
○ musnqzvt [email protected] 43 seconds ago 9a09f8a5 |
| 68 |
│ Revision C |
| 69 |
○ rsvnrznr [email protected] 43 seconds ago 5b490f30 |
| 70 |
│ Revision B |
| 71 |
○ tylynnzk [email protected] 43 seconds ago f26967c8 |
| 72 |
│ Revision A |
| 73 |
``` |
| 74 |
|
| 75 |
### How can I get `jj log` to show me what `git log` would show me? |
| 76 |
|
| 77 |
Use `jj log -r ..`. The `..` [operator] lists all visible commits in the repo, excluding the root (which is never interesting and is shared by all repos). |
| 78 |
|
| 79 |
### Can I monitor how `jj log` evolves? |
| 80 |
|
| 81 |
The simplest way to monitor how the history as shown by `jj log` evolves is by using the [watch(1)](https://man7.org/linux/man-pages/man1/watch.1.html) command (or [hwatch](https://github.com/blacknon/hwatch?tab=readme-ov-file#configuration) or [viddy](https://github.com/sachaos/viddy)). |
| 82 |
For example: |
| 83 |
|
| 84 |
```sh |
| 85 |
watch --color jj --ignore-working-copy log --color=always |
| 86 |
``` |
| 87 |
|
| 88 |
This will continuously update the (colored) log output in the terminal. |
| 89 |
The `--ignore-working-copy` option avoids conflicts with manual operations during the creation of snapshots. |
| 90 |
Martin used watch in a [tmux](https://github.com/tmux/tmux/wiki) pane during his presentation [Jujutsu - A Git-compatible VCS](https://www.youtube.com/watch?v=LV0JzI8IcCY). |
| 91 |
|
| 92 |
A similar result can be achieved with [watchexec](https://github.com/watchexec/watchexec), |
| 93 |
which triggers on op log changes instead of using a two-second interval: |
| 94 |
|
| 95 |
```sh |
| 96 |
watchexec --quiet --clear --restart --watch=.jj/repo/op_heads/heads --ignore-nothing --wrap-process=none -- jj --ignore-working-copy log |
| 97 |
``` |
| 98 |
|
| 99 |
Alternatively, you can use [jj-fzf](https://github.com/tim-janik/jj-fzf), where the central piece is the `jj log` view and common operations can be carried out via key bindings while the log view updates. |
| 100 |
|
| 101 |
The wiki lists additional TUIs and GUIs beyond the terminal: [GUI-and-TUI](https://github.com/jj-vcs/jj/wiki/GUI-and-TUI) |
| 102 |
|
| 103 |
### <a name="should-i-co-locate-my-repository"></a>Should I colocate my repository? |
| 104 |
|
| 105 |
Colocating a Jujutsu repository allows you to use both Jujutsu and Git in the |
| 106 |
same working copy. The benefits of doing so are: |
| 107 |
|
| 108 |
- You can use Git commands when you're not sure how to do something with |
| 109 |
Jujutsu, Jujutsu hasn't yet implemented a feature (e.g., tagging), or you |
| 110 |
simply prefer Git in some situations. |
| 111 |
|
| 112 |
- Tooling that expects a Git repository still works (IDEs, build tooling, etc.) |
| 113 |
|
| 114 |
The [colocation documentation describes the |
| 115 |
drawbacks](git-compatibility.md#colocated-jujutsugit-repos) but the most |
| 116 |
important ones are: |
| 117 |
|
| 118 |
- Interleaving `git` and `jj` commands may create confusing bookmark conflicts |
| 119 |
or divergent changes. |
| 120 |
|
| 121 |
- If the working copy commit or its parent contain any conflicted files, tools |
| 122 |
expecting a Git repo may interpret the commit contents or its diff in a wrong |
| 123 |
and confusing way. You should avoid doing mutating operations with Git tools |
| 124 |
and ignore the confusing information such tools present for conflicted commits |
| 125 |
(unless you are curious about [the details of how `jj` stores |
| 126 |
conflicts](technical/conflicts.md)). See |
| 127 |
[\#3979](https://github.com/jj-vcs/jj/issues/3979) for plans to improve |
| 128 |
this situation. |
| 129 |
|
| 130 |
- Jujutsu commands may be a little slower in very large repositories due to |
| 131 |
importing and exporting changes to Git. Most repositories are not noticeably |
| 132 |
affected by this. |
| 133 |
|
| 134 |
If you primarily use Jujutsu to modify the repository, the drawbacks are |
| 135 |
unlikely to affect you. Try colocating while you learn Jujutsu, then switch if |
| 136 |
you find a specific reason not to colocate. |
| 137 |
|
| 138 |
### `jj` is said to record the working copy after `jj log` and every other command. Where can I see these automatic "saves"? |
| 139 |
|
| 140 |
Indeed, every `jj` command updates the current "working-copy" revision, marked |
| 141 |
with `@` in `jj log`. You can notice this by how the [commit ID] of the |
| 142 |
working copy revision changes when it's updated. Note that, unless you move to |
| 143 |
another revision (with `jj new` or `jj edit`, for example), the [change ID] will |
| 144 |
not change. |
| 145 |
|
| 146 |
If you expected to see a historical view of your working copy changes in the |
| 147 |
parent-child relationships between commits you can see in `jj log`, this is |
| 148 |
simply not what they mean. What you can see in `jj log` is that after the |
| 149 |
working copy commit gets amended (after any edit), the commit ID changes. |
| 150 |
|
| 151 |
You can see the actual history of working copy changes using `jj evolog`. This |
| 152 |
will show the history of the commits that were previously the "working-copy |
| 153 |
commit", since the last time the change id of the working copy commit changed. |
| 154 |
The obsolete changes will be marked as "hidden". They are still accessible with |
| 155 |
any `jj` command (`jj diff`, for example), but you will need to use the commit |
| 156 |
id to refer to hidden commits. |
| 157 |
|
| 158 |
You can also use `jj evolog -r` on revisions that were previously the |
| 159 |
working-copy revisions (or on any other revisions). Use `jj evolog -p` as an |
| 160 |
easy way to see the evolution of the commit's contents. |
| 161 |
|
| 162 |
### Can I prevent Jujutsu from recording my unfinished work? I'm not ready to commit it. |
| 163 |
|
| 164 |
Jujutsu automatically records new files in the current working-copy commit and |
| 165 |
doesn't provide a way to prevent that. |
| 166 |
|
| 167 |
However, you can easily record intermediate drafts of your work. If you think |
| 168 |
you might want to go back to the current state of the working-copy commit, |
| 169 |
simply use `jj new`. There's no need for the commit to be "finished" or even |
| 170 |
have a description. |
| 171 |
|
| 172 |
Then future edits will go into a new working-copy commit on top of the now |
| 173 |
former working-copy commit. Whenever you are happy with another set of edits, |
| 174 |
use `jj squash` to amend the previous commit. |
| 175 |
|
| 176 |
If you have changes you _never_ want to put in a public commit, see: [How can I |
| 177 |
keep my scratch files in the repository without committing |
| 178 |
them?](#how-can-i-keep-my-scratch-files-in-the-repository-without-committing-them) |
| 179 |
|
| 180 |
For more options see the next question. |
| 181 |
|
| 182 |
### Can I interactively create a new commit from only some of the changes in the working copy, like `git add -p && git commit` or `hg commit -i`? |
| 183 |
|
| 184 |
Since the changes are already in the working-copy commit, the equivalent to |
| 185 |
`git add -p && git commit`/`git commit -p`/`hg commit -i` is to split the |
| 186 |
working-copy commit with `jj split -i` (or the practically identical |
| 187 |
`jj commit -i`). |
| 188 |
|
| 189 |
For the equivalent of `git commit --amend -p`/`hg amend -i`, use `jj squash -i`. |
| 190 |
|
| 191 |
### Is there something like `git rebase --interactive` or `hg histedit`? |
| 192 |
|
| 193 |
It is often sufficient to use some form of `jj rebase` with `-A/-B`. For |
| 194 |
example, if you have a linear chain of revisions `A` through `C` and want to |
| 195 |
move `C` before `B`, use `jj rebase -r C -B B`. See `jj help rebase` for more |
| 196 |
examples. |
| 197 |
|
| 198 |
For more complicated cases, try `jj arrange`. It is still under development, |
| 199 |
and will gain more features over time. |
| 200 |
|
| 201 |
To squash or split commits, use `jj squash` and `jj split`. |
| 202 |
|
| 203 |
### How can I keep my scratch files in the repository without committing them? |
| 204 |
|
| 205 |
You can set `snapshot.auto-track` to only start tracking new files matching the |
| 206 |
configured pattern (e.g. `"none()"`). Changes to already tracked files will |
| 207 |
still be snapshotted by every command. Files not matching the pattern can be |
| 208 |
tracked with `jj file track`. |
| 209 |
|
| 210 |
You can keep your notes and other scratch files in the repository, if you add |
| 211 |
a wildcard pattern to either the repo's `gitignore` or your global `gitignore`. |
| 212 |
Something like `*.scratch` or `*.scratchpad` should do, after that rename the |
| 213 |
files you want to keep around to match the pattern. |
| 214 |
|
| 215 |
If you keep your scratch files in their own directory with no tracked files, you |
| 216 |
can create a `.gitignore` file in that directory containing only `*`. This will |
| 217 |
ignore everything in the directory including the `.gitignore` file itself. |
| 218 |
|
| 219 |
If `$EDITOR` integration is important, something like `scratchpad.*` may be more |
| 220 |
helpful, as you can keep the filename extension intact (it matches |
| 221 |
`scratchpad.md`, `scratchpad.rs` and more). Another option is to add a directory |
| 222 |
which would store all your temporary files and notes to your configured global |
| 223 |
gitignore file. For example, you could add `scratch/` to it and then store |
| 224 |
arbitrary files in `<your-git-repo>/scratch/`. |
| 225 |
|
| 226 |
You can find more details on `gitignore` files [here][gitignore]. |
| 227 |
|
| 228 |
### How can I avoid committing my local-only changes to tracked files? |
| 229 |
|
| 230 |
Suppose your repository tracks a file like `secret_config.json`, and you make |
| 231 |
some changes to that file to work locally. Since Jujutsu automatically commits |
| 232 |
the working copy, there's no way to prevent Jujutsu from committing changes to |
| 233 |
the file. But, you never want to push those changes to the remote repository. |
| 234 |
|
| 235 |
One solution is to keep these changes in a separate commit branched from the |
| 236 |
trunk. To use those changes in your working copy, _merge_ the private commit |
| 237 |
into your branch. |
| 238 |
|
| 239 |
Suppose you have a commit "Add new feature": |
| 240 |
|
| 241 |
```shell |
| 242 |
$ jj log |
| 243 |
@ xxxxxxxx [email protected] 2024-08-21 11:13:21 ef612875 |
| 244 |
│ Add new feature |
| 245 |
◆ yyyyyyyy [email protected] 2024-08-21 11:13:09 main b624cf12 |
| 246 |
│ Existing work |
| 247 |
~ |
| 248 |
``` |
| 249 |
|
| 250 |
First, create a new commit branched from main and add your private changes: |
| 251 |
|
| 252 |
```shell |
| 253 |
$ jj new main -m "private: my credentials" |
| 254 |
Working copy (@) now at: wwwwwwww 861de9eb (empty) private: my credentials |
| 255 |
Parent commit (@-) : yyyyyyyy b624cf12 main | Existing work |
| 256 |
Added 0 files, modified 1 files, removed 0 files |
| 257 |
|
| 258 |
$ echo '{ "password": "p@ssw0rd1" }' > secret_config.json |
| 259 |
``` |
| 260 |
|
| 261 |
Now create a merge commit with the branch you're working on and the private |
| 262 |
commit: |
| 263 |
|
| 264 |
```shell |
| 265 |
$ jj new xxxxxxxx wwwwwwww |
| 266 |
Working copy (@) now at: vvvvvvvv ac4d9fbe (empty) (no description set) |
| 267 |
Parent commit (@-) : xxxxxxxx ef612875 Add new feature |
| 268 |
Parent commit (@-) : wwwwwwww 2106921e private: my credentials |
| 269 |
Added 0 files, modified 1 files, removed 0 files |
| 270 |
|
| 271 |
$ jj log |
| 272 |
@ vvvvvvvv [email protected] 2024-08-22 08:57:40 ac4d9fbe |
| 273 |
├─╮ (empty) (no description set) |
| 274 |
│ ○ wwwwwwww [email protected] 2024-08-22 08:57:40 2106921e |
| 275 |
│ │ private: my credentials |
| 276 |
○ │ xxxxxxxx [email protected] 2024-08-21 11:13:21 ef612875 |
| 277 |
├─╯ Add new feature |
| 278 |
◆ yyyyyyyy [email protected] 2024-08-21 11:13:09 main b624cf12 |
| 279 |
│ Existing work |
| 280 |
~ |
| 281 |
``` |
| 282 |
|
| 283 |
Now you're ready to work: |
| 284 |
|
| 285 |
- Your work in progress _xxxxxxxx_ is the first parent of the merge commit. |
| 286 |
- The private commit _wwwwwwww_ is the second parent of the merge commit. |
| 287 |
- The working copy (_vvvvvvvv_) contains changes from both. |
| 288 |
|
| 289 |
As you work, squash your changes using `jj squash --into xxxxxxxx`. |
| 290 |
|
| 291 |
If you need a new empty commit on top of `xxxxxxxx` you can use the |
| 292 |
`--insert-after` and `--insert-before` options (`-A` and `-B` for short): |
| 293 |
|
| 294 |
```shell |
| 295 |
# Insert a new commit after xxxxxxxx |
| 296 |
$ jj new --no-edit -A xxxxxxxx -m "Another feature" |
| 297 |
Working copy (@) now at: uuuuuuuu 1c3cff09 (empty) Another feature |
| 298 |
Parent commit (@-) : xxxxxxxx ef612875 Add new feature |
| 299 |
|
| 300 |
# Insert a new commit between yyyyyyyy and vvvvvvvv |
| 301 |
$ jj new --no-edit -A yyyyyyyy -B vvvvvvvv -m "Yet another feature" |
| 302 |
Working copy (@) now at: tttttttt 938ab831 (empty) Yet another feature |
| 303 |
Parent commit (@-) : yyyyyyyy b624cf12 Existing work |
| 304 |
``` |
| 305 |
|
| 306 |
To avoid pushing change _wwwwwwww_ by mistake, use the configuration |
| 307 |
[git.private-commits](config.md#set-of-private-commits): |
| 308 |
|
| 309 |
```shell |
| 310 |
jj config set --user git.private-commits "'''description('private:*')'''" |
| 311 |
``` |
| 312 |
|
| 313 |
### I accidentally changed files in the wrong commit, how do I move the recent changes into another commit? |
| 314 |
|
| 315 |
Let's say we are editing a commit for "featureA", and we forgot to run `jj |
| 316 |
new` or `jj commit` before doing some work that belongs in a new commit: |
| 317 |
|
| 318 |
```console |
| 319 |
$ jj log |
| 320 |
@ lnvvtrzo [email protected] 2025-02-28 21:01:10 31a347e0 |
| 321 |
│ featureA |
| 322 |
◆ zzzzzzzz root() 00000000 |
| 323 |
$ cat file # Oh no, the work on "feature B" should be in a separate commit! |
| 324 |
Done with feature A |
| 325 |
Working on feature B |
| 326 |
``` |
| 327 |
|
| 328 |
The goal is to restore change `lnvvtrzo` to its previous state and split the |
| 329 |
difference into a new child commit. |
| 330 |
|
| 331 |
#### Step 1: Find the commit ID for the "last good version" |
| 332 |
|
| 333 |
If you pushed `lnvvtrzo` already, then the version you probably want to restore |
| 334 |
is the version on the remote. For example, if the bookmark is `feature-a`, then |
| 335 |
the commit you want to restore is `feature-a@origin`. |
| 336 |
|
| 337 |
Otherwise, you can find [all the past versions of the working copy revision that |
| 338 |
`jj` has saved][predecessors] by running `jj evolog`, perhaps with the `--patch` |
| 339 |
option. The obsolete versions will be marked as "hidden" and will have the same |
| 340 |
change ID, but will have different commit IDs. This represents the [change] |
| 341 |
evolving over time. |
| 342 |
|
| 343 |
[predecessors]: |
| 344 |
#jj-is-said-to-record-the-working-copy-after-jj-log-and-every-other-command-where-can-i-see-these-automatic-saves |
| 345 |
|
| 346 |
For example, this is what the evolog might look like after you made two edits to |
| 347 |
the same change: |
| 348 |
|
| 349 |
```console |
| 350 |
$ # Note the word "hidden", the commit IDs on the right, |
| 351 |
$ # and the unchanging change ID on the left. |
| 352 |
$ jj evolog |
| 353 |
@ lnvvtrzo [email protected] 2025-02-28 21:01:10 31a347e0 |
| 354 |
│ featureA |
| 355 |
│ -- operation 3cb7392c092c snapshot working copy |
| 356 |
○ lnvvtrzo/1 [email protected] 2025-02-28 21:00:51 b8004ab8 (hidden) |
| 357 |
│ featureA |
| 358 |
│ -- operation 1280bfaec893 snapshot working copy |
| 359 |
○ lnvvtrzo/2 [email protected] 2025-02-28 20:50:05 e4d831d (hidden) |
| 360 |
(no description set) |
| 361 |
-- operation 0418a5aa94b5 snapshot working copy |
| 362 |
``` |
| 363 |
|
| 364 |
Since commit `b800` is hidden, it is considered obsolete and `jj log` (without |
| 365 |
arguments) will not show it. However, most `jj` operations work normally on |
| 366 |
such commits if you refer to them by their commit ID. Hidden commits can also |
| 367 |
be referred to by their change ID, but they require a |
| 368 |
[change offset][glossary_change_offset] to distinguish them (e.g. `b800` can |
| 369 |
also be referred to as `lnv/1`, as shown in the evolog). |
| 370 |
|
| 371 |
To find out which of these versions is the last time before we started working |
| 372 |
on feature B (the point where we should have created a new change, but failed to |
| 373 |
do so), we can look at the actual changes between the `evolog` commits by |
| 374 |
running `jj evolog --patch`: |
| 375 |
|
| 376 |
```console |
| 377 |
$ # When was the last saved point before we started working on feature B? |
| 378 |
$ jj evolog --patch --git # We use `--git` to make diffs clear without colors |
| 379 |
@ lnvvtrzo [email protected] 2025-02-28 21:01:10 31a347e0 |
| 380 |
│ featureA |
| 381 |
│ -- operation 3cb7392c092c snapshot working copy |
| 382 |
│ diff --git a/file b/file |
| 383 |
│ index 2b455c4207..2a7e05a01a 100644 |
| 384 |
│ --- a/file |
| 385 |
│ +++ b/file |
| 386 |
│ @@ -1,1 +1,2 @@ |
| 387 |
│ Done with feature A |
| 388 |
│ +Working on feature B |
| 389 |
○ lnvvtrzo/1 [email protected] 2025-02-28 21:00:51 b8004ab8 (hidden) |
| 390 |
│ featureA |
| 391 |
│ -- operation 1280bfaec893 snapshot working copy |
| 392 |
│ diff --git a/file b/file |
| 393 |
│ index cb61245109..2b455c4207 |
| 394 |
│ --- a/file |
| 395 |
│ +++ b/file |
| 396 |
│ @@ -1,1 +1,1 @@ |
| 397 |
│ -Working on feature A |
| 398 |
│ +Done with feature A |
| 399 |
○ lnvvtrzo/2 [email protected] 2025-02-28 20:50:05 e4d831d (hidden) |
| 400 |
(no description set) |
| 401 |
-- operation 0418a5aa94b5 snapshot working copy |
| 402 |
diff --git a/file b/file |
| 403 |
index 0000000000..cb61245109 |
| 404 |
--- /dev/null |
| 405 |
+++ b/file |
| 406 |
@@ 0,0 +1,1 @@ |
| 407 |
+Working on feature A |
| 408 |
``` |
| 409 |
|
| 410 |
In this example, the version of the change when we were actually done with |
| 411 |
feature A is when we edited the file to say "Done with feature A". This state |
| 412 |
was saved in the commit with ID `b80` (the second one in the list). The |
| 413 |
following edit (commit `31a`) belongs in a new change. |
| 414 |
|
| 415 |
#### Step 2: Create a new change on top of the original revision |
| 416 |
|
| 417 |
The "featureA" change is currently at commit `31a`: |
| 418 |
|
| 419 |
```console |
| 420 |
$ jj log |
| 421 |
@ lnvvtrzo [email protected] 2025-02-28 21:01:10 31a347e0 |
| 422 |
│ featureA |
| 423 |
◆ zzzzzzzz root() 00000000 |
| 424 |
``` |
| 425 |
|
| 426 |
We'd like to create a new "featureB" change with the contents of the current |
| 427 |
commit `31a`, and we'd like the "featureA" change to be reverted to its former |
| 428 |
state at commit `b80` (see step 1 above for how we found that commit ID). |
| 429 |
|
| 430 |
First, we create a new empty child commit on top of `b80`: |
| 431 |
|
| 432 |
```console |
| 433 |
$ jj new b80 -m "featureB" |
| 434 |
Working copy (@) now at: pvnrkl 47171aa (empty) featureB |
| 435 |
Parent commit (@-) : lnvvtr/1 b8004ab (divergent) featureA |
| 436 |
``` |
| 437 |
|
| 438 |
There are now two visible commits with change ID `lnvvtr` (commit `b8004ab` |
| 439 |
and `31a347e0`), so we call these [divergent][glossary_divergence]. Similarly |
| 440 |
to hidden commits, divergent commits also require a |
| 441 |
[change offset][glossary_change_offset] when using the change ID to refer to |
| 442 |
them, so you can see that `b8004ab` is still shown as `lnvvtr/1` in the output. |
| 443 |
This temporary divergence is okay and will be resolved in the next steps. |
| 444 |
|
| 445 |
[glossary_divergence]: glossary.md#divergent-change |
| 446 |
[glossary_change_offset]: glossary.md#change-offset |
| 447 |
|
| 448 |
Next, restore the contents of `31a347e0` into the working copy: |
| 449 |
|
| 450 |
```console |
| 451 |
$ jj restore --from 31a347e0 |
| 452 |
Working copy (@) now at: pvnrkl 468104c featureB |
| 453 |
Parent commit (@-) : lnvvtr/1 b8004ea (divergent) featureA |
| 454 |
$ cat file |
| 455 |
Done with feature A |
| 456 |
Working on feature B |
| 457 |
``` |
| 458 |
|
| 459 |
#### Step 3: Move any bookmarks to the original revision |
| 460 |
|
| 461 |
```console |
| 462 |
$ jj bookmark move --from 31a347e0 --to b8004ea8 |
| 463 |
``` |
| 464 |
|
| 465 |
#### Step 4: Abandon the unwanted revision |
| 466 |
|
| 467 |
```console |
| 468 |
$ jj abandon 31a347e0 |
| 469 |
``` |
| 470 |
|
| 471 |
Now, we have achieved the exact state we desired: |
| 472 |
|
| 473 |
``` |
| 474 |
$ jj log -p --git |
| 475 |
@ pvnrklkn [email protected] 2025-02-28 21:39:29 468104c2 |
| 476 |
│ featureB |
| 477 |
│ diff --git a/file b/file |
| 478 |
│ index 2b455c4207..2a7e05a01a 100644 |
| 479 |
│ --- a/file |
| 480 |
│ +++ b/file |
| 481 |
│ @@ -1,1 +1,2 @@ |
| 482 |
│ Done with feature A |
| 483 |
│ +Working on feature B |
| 484 |
○ lnvvtrzo [email protected] 2025-02-28 21:00:51 b8004ab8 |
| 485 |
│ featureA |
| 486 |
│ diff --git a/file b/file |
| 487 |
│ new file mode 100644 |
| 488 |
│ index 0000000000..2b455c4207 |
| 489 |
│ --- /dev/null |
| 490 |
│ +++ b/file |
| 491 |
│ @@ -0,0 +1,1 @@ |
| 492 |
│ +Done with feature A |
| 493 |
◆ zzzzzzzz root() 00000000 |
| 494 |
$ jj diff --from b80 --to @- # No output means these are identical |
| 495 |
$ jj diff --from 31a --to @ # No output means these are identical |
| 496 |
``` |
| 497 |
|
| 498 |
### How do I resume working on an existing change? |
| 499 |
|
| 500 |
There are two ways to resume working on an earlier change: `jj new` then `jj squash`, |
| 501 |
and `jj edit`. The first is generally recommended, but `jj edit` can be useful. When |
| 502 |
you use `jj edit`, the revision is directly amended with your new changes, making it |
| 503 |
difficult to tell what exactly you change. You should avoid using `jj edit` when the |
| 504 |
revision has a conflict, as you may accidentally break the plain-text annotations on |
| 505 |
your state without realizing. |
| 506 |
|
| 507 |
To start, use `jj new <rev>` to create a change based on that earlier revision. Make |
| 508 |
your edits, then use `jj squash` to update the earlier revision with those edits. |
| 509 |
For when you would use git stashing, use `jj edit <rev>` for expected behavior. |
| 510 |
Other workflows may prefer `jj edit` as well. |
| 511 |
|
| 512 |
### Why are most merge commits marked as "(empty)"? |
| 513 |
|
| 514 |
Jujutsu, like Git, is a snapshot-based VCS. That means that each commit |
| 515 |
logically records the state of all current files in the repo. The changes in a |
| 516 |
commit are not recorded but are instead calculated when needed by comparing the |
| 517 |
commit's state to the parent commit's state. Jujutsu defines the changes in a |
| 518 |
commit to be relative to the auto-merged parents (if there's only one parent, |
| 519 |
then that merge is trivial - it's the parent commit's state). As a result, a |
| 520 |
merge commit that was a clean merge (no conflict resolution, no additional |
| 521 |
changes) is considered empty. Conversely, if the merge commit contains conflict |
| 522 |
resolutions or additional changes, then it will be considered non-empty. |
| 523 |
|
| 524 |
This definition of the changes in a commit is used throughout Jujutsu. It's |
| 525 |
used by `jj diff -r` and `jj log -p` to show the changes in a commit. It's used |
| 526 |
by `jj rebase` to rebase the changes in a commit. It's used in `jj log` to |
| 527 |
indicate which commits are empty. It's used in the `files()` revset function |
| 528 |
(and by `jj log <path>`) to find commits that modify a certain path. And so on. |
| 529 |
|
| 530 |
### How do I revert a merge commit? `jj revert -r <merge>` does nothing |
| 531 |
|
| 532 |
Jujutsu defines the changes in a merge commit (and non-merge commits) as the |
| 533 |
changes made compared to the auto-merged parents. That means that merge commits |
| 534 |
are often empty. As a result, `jj revert` or a merge commit often results in an |
| 535 |
empty commit. To revert the changes merged in from the second parent, instead |
| 536 |
use `jj restore --from <first parent>` . |
| 537 |
|
| 538 |
Example: |
| 539 |
|
| 540 |
```text |
| 541 |
@ |
| 542 |
| |
| 543 |
C |
| 544 |
| \ |
| 545 |
B D |
| 546 |
|/ |
| 547 |
A |
| 548 |
``` |
| 549 |
|
| 550 |
To revert the merge in `C`, create a new commit with `jj new C`, |
| 551 |
then `jj restore --from B`, and then describe the message |
| 552 |
with something like `jj desc -m "Revert the merge of D into B`. Now, commit `@` |
| 553 |
undoes the merge of `D` into `B`. If necessary, you can now rebase it |
| 554 |
elsewhere, e.g. `jj rebase -r @ -o main`. |
| 555 |
|
| 556 |
### How do I deal with divergent changes? |
| 557 |
|
| 558 |
See: [Handling divergent commits](guides/divergence.md). |
| 559 |
|
| 560 |
### How do I deal with conflicted bookmarks ('??' after bookmark name)? |
| 561 |
|
| 562 |
A [conflicted bookmark][bookmarks_conflicts] is a bookmark that refers to multiple |
| 563 |
different commits because jj couldn't fully resolve its desired position. |
| 564 |
Resolving conflicted bookmarks is usually done by setting the bookmark to the |
| 565 |
correct commit using `jj bookmark move <name> --to <commit ID>`. |
| 566 |
|
| 567 |
Usually, the different commits associated with the conflicted bookmark should all |
| 568 |
appear in the log, but if they don't you can use `jj bookmark list`to show all the |
| 569 |
commits associated with it. |
| 570 |
|
| 571 |
### I'm experiencing `jj` command issues in a Vite/Vitest project, how do I fix this? |
| 572 |
|
| 573 |
When using Vite or Vitest in a Jujutsu repository, you may experience: |
| 574 |
- Very slow vitest startup times |
| 575 |
- Timeout errors in `jj` terminal commands |
| 576 |
- Errors with 3rd party visual tools like `jjk` or `visual-jj` |
| 577 |
- Corrupted `working_copy.lock` files |
| 578 |
|
| 579 |
This happens because Vite watches the `.jj` directory where Jujutsu stores its internal state. |
| 580 |
This creates unnecessary overhead as Vite processes Jujutsu's frequent internal file changes, |
| 581 |
which can slow down both tools and occasionally cause file access conflicts. |
| 582 |
|
| 583 |
**Solution**: Configure Vite to ignore the `.jj` directory by adding it to the |
| 584 |
`server.watch.ignored` array inside your Vite configuration, for example: |
| 585 |
|
| 586 |
```js |
| 587 |
// vite.config.js |
| 588 |
export default defineConfig({ |
| 589 |
// ... other config like plugins, test setup, etc. |
| 590 |
server: { |
| 591 |
watch: { |
| 592 |
ignored: [ |
| 593 |
"**/.jj/**", |
| 594 |
] |
| 595 |
} |
| 596 |
}, |
| 597 |
}) |
| 598 |
``` |
| 599 |
|
| 600 |
Note: There was a [request](https://github.com/vitejs/vite/issues/20036) to include `.jj` |
| 601 |
in the default ignore list, but manual configuration remains the recommended approach. |
| 602 |
|
| 603 |
### How can I manually trigger (e.g., periodic) snapshots? |
| 604 |
|
| 605 |
Most `jj` commands will automatically snapshot the working copy at the start of |
| 606 |
the command if needed. However, if you'd like to manually trigger a snapshot for |
| 607 |
whatever reason, such as for scripting, prompt info, or periodic snapshots in |
| 608 |
parallel with something like a |
| 609 |
[`watch` command](#can-i-monitor-how-jj-log-evolves), you can run |
| 610 |
`jj util snapshot`. By default this command will print whether a snapshot was |
| 611 |
taken, which you can silence with the global `--quiet` flag. This command is |
| 612 |
likely most useful for scripting rather than for running on the command line by |
| 613 |
a human. |
| 614 |
|
| 615 |
If you want to see the ID of the current operation after this command, it would |
| 616 |
be simpler to run `jj operation log --limit 1` directly, since that command also |
| 617 |
takes a snapshot if needed. |
| 618 |
|
| 619 |
### I want to write a tool which integrates with Jujutsu. Should I use the library or parse the CLI? |
| 620 |
|
| 621 |
There are some trade-offs and there is no definitive answer yet. |
| 622 |
|
| 623 |
* Using `jj-lib` avoids parsing command output and makes error handling easier. |
| 624 |
* `jj-lib` is not a stable API, so you may have to make changes to your tool |
| 625 |
when the API changes. |
| 626 |
* The CLI is not stable either, so you may need to make your tool detect the |
| 627 |
different versions and call the right command. |
| 628 |
* Using the CLI means that your tool will work with custom-built `jj` binaries, |
| 629 |
like the one at Google (if you're using the library, you will not be able to |
| 630 |
detect custom backends and more). |
| 631 |
|
| 632 |
### Why is Jujutsu a separate project? Why were the features not contributed to Git instead? |
| 633 |
|
| 634 |
The project started as an experiment with the idea of representing the working |
| 635 |
copy by a regular commit. I (@martinvonz) considered how this feature would |
| 636 |
impact the Git CLI if it were added to Git. My conclusion was that it would |
| 637 |
effectively result in deprecating most existing Git commands and flags in favor |
| 638 |
of new commands and flags, especially considering I wanted to also support |
| 639 |
revsets. This seemed unlikely to be accepted by the Git project. |
| 640 |
|
| 641 |
[bookmarks_conflicts]: bookmarks.md#conflicts |
| 642 |
|
| 643 |
[change]: glossary.md#change |
| 644 |
[change ID]: glossary.md#change-id |
| 645 |
[colocated]: glossary.md#colocated-workspaces |
| 646 |
[commit ID]: glossary.md#commit-id |
| 647 |
[commits]: glossary.md#commit |
| 648 |
[config]: config.md |
| 649 |
|
| 650 |
[gerrit-integration]: https://gist.github.com/thoughtpolice/8f2fd36ae17cd11b8e7bd93a70e31ad6 |
| 651 |
[gitignore]: https://git-scm.com/docs/gitignore |
| 652 |
|
| 653 |
[operator]: revsets.md#operators |
| 654 |
|
| 655 |
[revsets]: revsets.md |
| 656 |
|
| 657 |
[templates]: templates.md |