Debian Codegraph @

docs/tutorial.md

raw ◀ ▶
1 Debian patch touch this file
1 # Tutorial
2
3 > **Hint:** This tutorial covers the basics accurately, but since it was
4 > written Jujutsu has gained many new features. For a tutorial covering a wider
5 > range of features, you may find the (not quite finished) [tutorial by Steve
6 > Klabnik](https://steveklabnik.github.io/jujutsu-tutorial/) helpful. If you're
7 > looking for a tutorial that doesn't require experience with Git, take a look
8 > at [Jujutsu for everyone](https://jj-for-everyone.github.io).
9
10 This text assumes that the reader is familiar with Git.
11
12 ## Preparation
13
14 If you haven't already, make sure you
15 [install and configure Jujutsu](install-and-setup.md).
16
17 ## Cloning a Git repository
18
19 > **Hint:** Most identifiers used in this tutorial will be different when you
20 > try this at home!
21
22 Let's start by cloning GitHub's Hello-World repo using `jj`:
23
24 ```shell
25 # Note the "git" before "clone" (there is no support for cloning native jj
26 # repos yet)
27 $ jj git clone https://github.com/octocat/Hello-World
28 Fetching into new repo in "/tmp/tmp.O1DWMiaKd4/Hello-World"
29 remote: Enumerating objects: 13, done.
30 remote: Total 13 (delta 0), reused 0 (delta 0), pack-reused 13 (from 1)
31 bookmark: master@origin [new] untracked
32 bookmark: octocat-patch-1@origin [new] untracked
33 bookmark: test@origin [new] untracked
34 Setting the revset alias `trunk()` to `master@origin`
35 Working copy (@) now at: kntqzsqt d7439b06 (empty) (no description set)
36 Parent commit (@-) : orrkosyo 7fd1a60b master | (empty) Merge pull request #6 from Spaceghost/patch-1
37 Added 1 files, modified 0 files, removed 0 files
38 $ cd Hello-World
39 ```
40
41 Running `jj st` (short for `jj status`) now yields something like this:
42
43 ```shell
44 $ jj st
45 The working copy has no changes.
46 Working copy (@) : kntqzsqt d7439b06 (empty) (no description set)
47 Parent commit (@-): orrkosyo 7fd1a60b master | (empty) Merge pull request #6 from Spaceghost/patch-1
48 ```
49
50 Let's look at that output as it introduces new concepts. You can see two
51 commits: Parent and working copy. Both are identified using two separate
52 identifiers: the "change ID" and the "commit ID".
53
54 The parent commit, for example, has the change ID `orrkosyo` and the commit ID
55 `7fd1a60b`.
56
57 > **Git users:** The commit ID/hash is what you're used to from Git and should
58 > match what you see when you look at the repository using `git log` in a Git
59 > checkout of the repository.
60 > The change ID however, is a new concept, unique to Jujutsu.
61
62 We can also see from the output above that our working copy is an actual commit
63 with a commit ID (`d7439b06` in the example). When you make a change in the
64 working copy, the working-copy commit gets automatically amended by the next
65 `jj` command.
66
67 > **Git users:** This is a huge difference from Git where the working copy is a
68 > separate concept and not yet a commit.
69
70 ## Changes
71
72 A change is a commit that can evolve while keeping a stable identifier (similar
73 to Gerrit's Change-Id). In other words: You can make changes to files in a
74 change, resulting in a new commit hash, but the change ID will remain the same.
75
76 You can see that our clone operation automatically created a new change:
77
78 ```shell
79 Working copy (@) : kntqzsqt d7439b06 (empty) (no description set)
80 ```
81
82 This new change has the ID `kntqzsqt` and it is currently empty (contains no
83 changes compared to the parent) and has no description.
84
85 ## Creating our first change
86
87 Let's say we want to edit the `README` file in the repo to say "Goodbye"
88 instead of "Hello". Start by describing the change (adding a commit message) so
89 we don't forget what we're working on:
90
91 ```shell
•92 # This brings up $EDITOR (or `editor` or `Notepad` by default).
93 # Enter something like "Say goodbye" in the editor and then save the file and close
94 # the editor.
95 $ jj describe
96 Working copy (@) now at: kntqzsqt e427edcf (empty) Say goodbye
97 Parent commit (@-) : orrkosyo 7fd1a60b master | (empty) Merge pull request #6 from Spaceghost/patch-1
98 ```
99
100 Now make the change in the README:
101
102 ```shell
103 # Adjust as necessary for compatibility with your flavor of `sed`
104 $ sed -i 's/Hello/Goodbye/' README
105 $ jj st
106 Working copy changes:
107 M README
108 Working copy (@) : kntqzsqt 5d39e19d Say goodbye
109 Parent commit (@-): orrkosyo 7fd1a60b master | (empty) Merge pull request #6 from Spaceghost/patch-1
110 ```
111
112 Note that you didn't have to tell Jujutsu to add the change like you would with
113 `git add`. You actually don't even need to tell it when you add new files or
114 remove existing files. To untrack a path, add it to your `.gitignore` and run
115 `jj file untrack <path>`.
116
117 Also note that the commit hash for our current change (`kntqzsqt`) changed from
118 `e427edcf` to `5d39e19d`!
119
120 To see the diff, run `jj diff`:
121
122 ```shell
123 $ jj diff --git # Feel free to skip the `--git` flag
124 diff --git a/README b/README
125 index 980a0d5f19..1ce3f81130 100644
126 --- a/README
127 +++ b/README
128 @@ -1,1 +1,1 @@
129 -Hello World!
130 +Goodbye World!
131 ```
132
133 Jujutsu's diff format currently defaults to inline coloring of the diff (like
134 `git diff --color-words`), so we used `--git` above to make the diff readable in
135 this tutorial.
136
137 As you may have noticed, the working-copy commit's ID changed both when we
138 edited the description and when we edited the README. However, the parent commit
139 stayed the same. Each change to the working-copy commit amends the previous
140 version. So how do we tell Jujutsu that we are done amending the current change
141 and want to start working on a new one? That is what `jj new` is for. That will
142 create a new commit on top of your current working-copy commit. The new commit
143 is for the working-copy changes.
144
145 So, let's say we're now done with this change, so we create a new change:
146
147 ```shell
148 $ jj new
149 Working copy (@) now at: mpqrykyp aef4df99 (empty) (no description set)
150 Parent commit (@-) : kntqzsqt 5d39e19d Say goodbye
151 $ jj st
152 The working copy has no changes.
153 Working copy (@) : mpqrykyp aef4df99 (empty) (no description set)
154 Parent commit (@-): kntqzsqt 5d39e19d Say goodbye
155 ```
156
157 If we later realize that we want to make further changes, we can make them in
158 the working copy and then run `jj squash`. That command squashes (moves) the
159 changes from a given commit into its parent commit. Like most commands, it acts
160 on the working-copy commit by default. When run on the working-copy commit, it
161 behaves very similar to `git commit --amend`.
162
163 Alternatively, we can use `jj edit <commit>` to resume editing a commit in the
164 working copy. Any further changes in the working copy will then amend the
165 commit. Whether you choose to create a new change and squash, or to edit,
166 typically depends on how done you are with the change; if the change is almost
167 done, it makes sense to use `jj new` so you can easily review your adjustments
168 with `jj diff` before running `jj squash`.
169
170 To view how a change has evolved over time, we can use `jj evolog` to see each
171 recorded change for the current commit. This records changes to the working
172 copy, message, squashes, rebases, etc.
173
174 ## The log command and "revsets"
175
176 You're probably familiar with `git log`. Jujutsu has very similar functionality
177 in its `jj log` command:
178
179 ```shell
180 $ jj log
181 @ mpqrykyp [email protected] 2023-02-12 15:00:22 aef4df99
182 │ (empty) (no description set)
183 ○ kntqzsqt [email protected] 2023-02-12 14:56:59 5d39e19d
184 │ Say goodbye
185 ◆ orrkosyo [email protected] 2012-03-06 15:06:50 master 7fd1a60b
186 │ (empty) Merge pull request #6 from Spaceghost/patch-1
187 ~
188 ```
189
190 The `@` indicates the working-copy commit. The first ID on a line
191 (e.g. "mpqrykyp" above) is the change ID. The second ID is the commit ID. You
192 can give either ID to commands that take revisions as arguments. We will
193 generally prefer change IDs because they stay the same when the commit is
194 rewritten.
195
196 By default, `jj log` lists your local commits, with some remote commits added
197 for context. The `~` indicates that the commit has parents that are not included
198 in the graph. We can use the `--revisions`/`-r` flag to select a different set
199 of revisions to list. The flag accepts a ["revset"](revsets.md), which is an
200 expression in a simple language for specifying revisions. For example, `@`
201 refers to the working-copy commit, `root()` refers to the root commit,
202 `bookmarks()` refers to all commits pointed to by bookmarks (similar to Git's
203 branches). We can combine expressions with `|` for union, `&` for intersection
204 and `~` for difference. For example:
205
206 ```shell
207 $ jj log -r '@ | root() | bookmarks()'
208 @ mpqrykyp [email protected] 2023-02-12 15:00:22 aef4df99
209 │ (empty) (no description set)
210 ~ (elided revisions)
211 ◆ orrkosyo [email protected] 2012-03-06 15:06:50 master 7fd1a60b
212 │ (empty) Merge pull request #6 from Spaceghost/patch-1
213 ~ (elided revisions)
214 ◆ zzzzzzzz root() 00000000
215 ```
216
217 The `00000000` commit (change ID `zzzzzzzz`) is a virtual commit that's called
218 the "root commit". It's the root commit of every repo. The `root()`
219 function in the revset matches it.
220
221 There are also operators for getting the parents (`foo-`), children (`foo+`),
222 ancestors (`::foo`), descendants (`foo::`), DAG range (`foo::bar`, like
223 `git log --ancestry-path`), range (`foo..bar`, same as Git's). See
224 [the revset documentation](revsets.md) for all revset operators and functions.
225
226 > **Hint:** If the default `jj log` omits some commits you expect to see, you
227 > can always run `jj log -r ::` (or, equivalently, `jj log -r 'all()'`) to see
228 > all the commits.
229
230 ## Conflicts
231
232 Now let's see how Jujutsu deals with merge conflicts. We'll start by making some
233 commits. We use `jj new` with the `--message`/`-m` option to set change
234 descriptions (commit messages) right away.
235
236 ```shell
237 # Start creating a chain of commits off of the `master` bookmark
238 $ jj new master -m A; echo a > file1
239 Working copy (@) now at: nuvyytnq 00a2aeed (empty) A
240 Parent commit (@-) : orrkosyo 7fd1a60b master | (empty) Merge pull request #6 from Spaceghost/patch-1
241 Added 0 files, modified 1 files, removed 0 files
242 $ jj new -m B1; echo b1 > file1
243 Working copy (@) now at: ovknlmro 967d9f9f (empty) B1
244 Parent commit (@-) : nuvyytnq 5dda2f09 A
245 $ jj new -m B2; echo b2 > file1
246 Working copy (@) now at: puqltutt 8ebeaffa (empty) B2
247 Parent commit (@-) : ovknlmro 7d7c6e6b B1
248 $ jj new -m C; echo c > file2
249 Working copy (@) now at: qzvqqupx 62a3c6d3 (empty) C
250 Parent commit (@-) : puqltutt daa6ffd5 B2
251 $ jj log
252 @ qzvqqupx [email protected] 2023-02-12 15:07:41 2370ddf3
253 │ C
254 ○ puqltutt [email protected] 2023-02-12 15:07:33 daa6ffd5
255 │ B2
256 ○ ovknlmro [email protected] 2023-02-12 15:07:24 7d7c6e6b
257 │ B1
258 ○ nuvyytnq [email protected] 2023-02-12 15:07:05 5dda2f09
259 │ A
260 │ ○ kntqzsqt [email protected] 2023-02-12 14:56:59 5d39e19d
261 ├─╯ Say goodbye
262 ◆ orrkosyo [email protected] 2012-03-06 15:06:50 master 7fd1a60b
263 │ (empty) Merge pull request #6 from Spaceghost/patch-1
264 ~
265 ```
266
267 We now have a few commits, where A, B1, and B2 modify the same file, while C
268 modifies a different file. Let's now rebase B2 directly onto A. We use the
269 `--source`/`-s` option on the change ID of B2, and `--onto`/`-o` option on A.
270
271 ```shell
272 $ jj rebase -s puqltutt -o nuvyytnq # Replace the IDs by what you have for B2 and A
273 Rebased 2 commits to destination
274 Working copy (@) now at: qzvqqupx 1978b534 (conflict) C
275 Parent commit (@-) : puqltutt f7fb5943 (conflict) B2
276 Added 0 files, modified 1 files, removed 0 files
277 Warning: There are unresolved conflicts at these paths:
278 file1 2-sided conflict
279 New conflicts appeared in 2 commits:
280 qzvqqupx 1978b534 (conflict) C
281 puqltutt f7fb5943 (conflict) B2
282 Hint: To resolve the conflicts, start by creating a commit on top of
283 the first conflicted commit:
284 jj new puqltutt
285 Then use `jj resolve`, or edit the conflict markers in the file directly.
286 Once the conflicts are resolved, you can inspect the result with `jj diff`.
287 Then run `jj squash` to move the resolution into the conflicted commit.
288
289 $ jj log
290 @ qzvqqupx [email protected] 2023-02-12 15:08:33 1978b534 (conflict)
291 │ C
292 × puqltutt [email protected] 2023-02-12 15:08:33 f7fb5943 (conflict)
293 │ B2
294 │ ○ ovknlmro [email protected] 2023-02-12 15:07:24 7d7c6e6b
295 ├─╯ B1
296 ○ nuvyytnq [email protected] 2023-02-12 15:07:05 5dda2f09
297 │ A
298 │ ○ kntqzsqt [email protected] 2023-02-12 14:56:59 5d39e19d
299 ├─╯ Say goodbye
300 ◆ orrkosyo [email protected] 2012-03-06 15:06:50 master 7fd1a60b
301 │ (empty) Merge pull request #6 from Spaceghost/patch-1
302 ~
303 ```
304
305 There are several things worth noting here. First, the `jj rebase` command said
306 "Rebased 2 commits". That's because we asked it to rebase commit B2 with the
307 `-s` option, which also rebases descendants (commit C in this case). Second,
308 because B2 modified the same file (and word) as B1, rebasing it resulted in
309 conflicts, as the output indicates. Third, the conflicts did not prevent the
310 rebase from completing successfully, nor did it prevent C from getting rebased
311 on top.
312
313 Now let's resolve the conflict in B2. We'll do that by creating a new commit on
314 top of B2. Once we've resolved the conflict, we'll squash the conflict
315 resolution into the conflicted B2. That might look like this:
316
317 ```shell
318 $ jj new puqltutt # Replace the ID by what you have for B2
319 Working copy (@) now at: zxoosnnp c7068d1c (conflict) (empty) (no description set)
320 Parent commit (@-) : puqltutt f7fb5943 (conflict) B2
321 Added 0 files, modified 0 files, removed 1 files
322 Warning: There are unresolved conflicts at these paths:
323 file1 2-sided conflict
324
325 $ jj st
326 The working copy has no changes.
327 Working copy (@) : zxoosnnp c7068d1c (conflict) (empty) (no description set)
328 Parent commit (@-): puqltutt f7fb5943 (conflict) B2
329 Warning: There are unresolved conflicts at these paths:
330 file1 2-sided conflict
331 Hint: To resolve the conflicts, start by creating a commit on top of
332 the conflicted commit:
333 jj new puqltutt
334 Then use `jj resolve`, or edit the conflict markers in the file directly.
335 Once the conflicts are resolved, you can inspect the result with `jj diff`.
336 Then run `jj squash` to move the resolution into the conflicted commit.
337
338 $ cat file1
339 <<<<<<< conflict 1 of 1
340 %%%%%%% diff from: ovknlmro 7d7c6e6b "B1" (parents of rebased revision)
341 \\\\\\\ to: nuvyytnq 5dda2f09 "A" (rebase destination)
342 -b1
343 +a
344 +++++++ puqltutt daa6ffd5 "B2" (rebased revision)
345 b2
346 >>>>>>> conflict 1 of 1 ends
347
348 $ echo resolved > file1
349
350 $ jj st
351 Working copy changes:
352 M file1
353 Working copy (@) : zxoosnnp c2a31a06 (no description set)
354 Parent commit (@-): puqltutt f7fb5943 (conflict) B2
355 Hint: Conflict in parent commit has been resolved in working copy
356
357 $ jj squash
358 Rebased 1 descendant commits
359 Working copy (@) now at: ntxxqymr e3c279cc (empty) (no description set)
360 Parent commit (@-) : puqltutt 2c7a658e B2
361 Existing conflicts were resolved or abandoned from 2 commits.
362
363 $ jj log
364 @ ntxxqymr [email protected] 2023-02-12 19:34:09 e3c279cc
365 │ (empty) (no description set)
366 │ ○ qzvqqupx [email protected] 2023-02-12 19:34:09 b9da9d28
367 ├─╯ C
368 ○ puqltutt [email protected] 2023-02-12 19:34:09 2c7a658e
369 │ B2
370 │ ○ ovknlmro [email protected] 2023-02-12 15:07:24 7d7c6e6b
371 ├─╯ B1
372 ○ nuvyytnq [email protected] 2023-02-12 15:07:05 5dda2f09
373 │ A
374 │ ○ kntqzsqt [email protected] 2023-02-12 14:56:59 5d39e19d
375 ├─╯ Say goodbye
376 ◆ orrkosyo [email protected] 2012-03-06 15:06:50 master 7fd1a60b
377 │ (empty) Merge pull request #6 from Spaceghost/patch-1
378 ~
379 ```
380
381 Note that commit C automatically got rebased on top of the resolved B2, and that
382 C is also resolved (since it modified only a different file).
383
384 By the way, if we want to get rid of B1 now, we can run `jj abandon
385 ovknlmro`. That will hide the commit from the log output and will rebase any
386 descendants to its parent.
387
388 ## The operation log
389
390 Jujutsu keeps a record of all changes you've made to the repo in what's called
391 the "operation log". Use the `jj op` (short for `jj operation`) family of
392 commands to interact with it. To list the operations, use `jj op log`:
393
394 ```shell
395 $ jj op log
396 @ d3b77addea49 [email protected] 3 minutes ago, lasted 3 milliseconds
397 │ squash commits into f7fb5943a6b9460eb106dba2fac5cac1625c6f7a
398 │ args: jj squash
399 ○ 6fc1873c1180 [email protected] 3 minutes ago, lasted 1 milliseconds
400 │ snapshot working copy
401 │ args: jj st
402 ○ ed91f7bcc1fb [email protected] 6 minutes ago, lasted 1 milliseconds
403 │ new empty commit
404 │ args: jj new puqltutt
405 ○ 367400773f87 [email protected] 12 minutes ago, lasted 3 milliseconds
406 │ rebase commit daa6ffd5a09a8a7d09a65796194e69b7ed0a566d and descendants
407 │ args: jj rebase -s puqltutt -o nuvyytnq
408 [many more lines]
409 ```
410
411 The most useful command is `jj undo`, which will undo your last operation.
412
413 ```shell
414 $ jj undo
415 Reverted operation: d3b77addea49 (2025-05-12 00:27:27) squash commits into f7fb5943a6b9460eb106dba2fac5cac1625c6f7a
416 Working copy (@) now at: zxoosnnp 63874fe6 (no description set)
417 Parent commit (@-) : puqltutt f7fb5943 (conflict) B2
418 New conflicts appeared in 2 commits:
419 qzvqqupx 1978b534 (conflict) C
420 puqltutt f7fb5943 (conflict) B2
421 Hint: To resolve the conflicts, start by creating a commit on top of
422 the first conflicted commit:
423 jj new puqltutt
424 Then use `jj resolve`, or edit the conflict markers in the file directly.
425 Once the conflicts are resolved, you can inspect the result with `jj diff`.
426 Then run `jj squash` to move the resolution into the conflicted commit.
427
428 $ jj log
429 @ zxoosnnp [email protected] 2023-02-12 19:34:09 63874fe6
430 │ (no description set)
431 │ × qzvqqupx [email protected] 2023-02-12 15:08:33 1978b534 (conflict)
432 ├─╯ C
433 × puqltutt [email protected] 2023-02-12 15:08:33 f7fb5943 (conflict)
434 │ B2
435 │ ○ ovknlmro [email protected] 2023-02-12 15:07:24 7d7c6e6b
436 ├─╯ B1
437 ○ nuvyytnq [email protected] 2023-02-12 15:07:05 5dda2f09
438 │ A
439 │ ○ kntqzsqt [email protected] 2023-02-12 14:56:59 5d39e19d
440 ├─╯ Say goodbye
441 ◆ orrkosyo [email protected] 2012-03-06 15:06:50 master 7fd1a60b
442 │ (empty) Merge pull request #6 from Spaceghost/patch-1
443 ~
444 ```
445
446 As you can perhaps see, that undid the `jj squash` invocation we used for
447 squashing the conflict resolution into commit B2 earlier. Notice that it also
448 updated the working copy.
449
450 You can also view the repo the way it looked after some earlier operation. For
451 example, if you want to see `jj log` output right after the `jj rebase`
452 operation, try `jj log --at-op=367400773f87` but use the hash from your own
453 `jj op log`.
454
455 ## Moving content changes between commits
456
457 You have already seen how `jj squash` can combine the changes from two commits
458 into one. There are several other commands for changing the contents of existing
459 commits.
460
461 We'll need some more complex content to test these commands, so let's create a
462 few more commits:
463
464 ```shell
465 $ jj new master -m abc; printf 'a\nb\nc\n' > file
466 Working copy (@) now at: ztqrpvnw f94e49cf (empty) abc
467 Parent commit (@-) : orrkosyo 7fd1a60b master | (empty) Merge pull request #6 from Spaceghost/patch-1
468 Added 0 files, modified 0 files, removed 1 files
469
470 $ jj new -m ABC; printf 'A\nB\nc\n' > file
471 Working copy (@) now at: kwtuwqnm 6f30cd1f (empty) ABC
472 Parent commit (@-) : ztqrpvnw 51002261 abc
473
474 $ jj new -m ABCD; printf 'A\nB\nC\nD\n' > file
475 Working copy (@) now at: mrxqplyk a6749154 (empty) ABCD
476 Parent commit (@-) : kwtuwqnm 30aecc08 ABC
477
478 $ jj log -r master::@
479 @ mrxqplyk [email protected] 2023-02-12 19:38:21 b98c607b
480 │ ABCD
481 ○ kwtuwqnm [email protected] 2023-02-12 19:38:12 30aecc08
482 │ ABC
483 ○ ztqrpvnw [email protected] 2023-02-12 19:38:03 51002261
484 │ abc
485 ◆ orrkosyo [email protected] 2012-03-06 15:06:50 master 7fd1a60b
486 │ (empty) Merge pull request #6 from Spaceghost/patch-1
487 ~
488 ```
489
490 We "forgot" to capitalize "c" in the second commit when we capitalized the other
491 letters. We then fixed that in the third commit when we also added "D". It would
492 be cleaner to move the capitalization of "c" into the second commit. We can do
493 that by running `jj squash` with the `--interactive`/`-i` option on the third
494 commit. Remember that `jj squash` moves all the changes from one commit into its
495 parent. `jj squash -i` moves only part of the changes into its parent. Now try
496 that:
497
498 ```shell
499 $ jj squash -i
500 Hint: Using default editor ':builtin'; run `jj config set --user ui.diff-editor :builtin` to disable this message.
501 Rebased 1 descendant commits
502 Working copy (@) now at: mrxqplyk 52a6c7fd ABCD
503 Parent commit (@-) : kwtuwqnm 643061ac ABC
504 ```
505
506 That will bring up the built-in diff editor[^alternative_diff_editors] with a
507 diff of the changes in the "ABCD" commit. Expand the file by clicking on `(+)`
508 or with right arrow, then select the sections/line to include by clicking or
509 using space. Once complete, press `c` to confirm changes, or `q` to exit without
510 saving. You can also use the mouse to click on the menu items to see more
511 options (keyboard navigation is currently limited).
512
513 [^alternative_diff_editors]: There are many other diff editors you could use.
514 For example, if you have [Meld](https://meldmerge.org) installed and in the
515 PATH, you can use it via `jj squash -i --tool meld` or a fancier config with `jj
516 squash -i --tool meld-3`. You can configure the default with the
517 [`ui.diff-editor` option](config.md#editing-diffs); those docs also explain how
518 to specify a path to an executable if it is not in the PATH.
519
520 If we look at the diff of the second commit, we now see that all three lines got
521 capitalized:
522
523 ```shell
524 $ jj diff -r @- --git
525 diff --git a/file b/file
526 index de980441c3..b1e67221af 100644
527 --- a/file
528 +++ b/file
529 @@ -1,3 +1,3 @@
530 -a
531 -b
532 -c
533 +A
534 +B
535 +C
536 ```
537
538 The child change ("ABCD" in our case) will have the same content *state* after
539 the `jj squash` command. That means that you can move any changes you want into
540 the parent change, even if they touch the same word, and it won't cause any
541 conflicts.
542
543 Let's try one final command for changing the contents of an existing commit. That
544 command is `jj diffedit`, which lets you edit the changes in a commit without
545 checking it out.
546
547 ```shell
548 $ jj diffedit -r @-
549 Hint: Using default editor ':builtin'; run `jj config set --user ui.diff-editor :builtin` to disable this message.
550 Rebased 1 descendant commits
551 Working copy (@) now at: mrxqplyk 1c72cd50 (conflict) ABCD
552 Parent commit (@-) : kwtuwqnm 70985eaa ABC
553 Added 0 files, modified 1 files, removed 0 files
554 Warning: There are unresolved conflicts at these paths:
555 file 2-sided conflict
556 New conflicts appeared in 1 commits:
557 mrxqplyk 1c72cd50 (conflict) ABCD
558 Hint: To resolve the conflicts, start by creating a commit on top of
559 the conflicted commit:
560 jj new mrxqplyk
561 Then use `jj resolve`, or edit the conflict markers in the file directly.
562 Once the conflicts are resolved, you can inspect the result with `jj diff`.
563 Then run `jj squash` to move the resolution into the conflicted commit.
564 ```
565
566 In the diff editor, use the arrow keys and spacebar to select all lines but the
567 last. Press 'c' to save the changes and close it. You can now inspect the
568 rewritten commit with `jj diff -r @-` again, and you should see your deletion of
569 the last line. Unlike `jj squash -i`, which left the content state of the commit
570 unchanged, `jj diffedit` (typically) results in a different state, which means
571 that descendant commits may have conflicts.
572
573 Another command for rewriting contents of existing commits is `jj split`. Now
574 that you've seen how `jj squash -i` and `jj diffedit` work, you can hopefully
575 figure out how it works (with the help of the instructions in the diff).