Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Dispatching Edits from Megamerges

Important

Where you start believing in magic.

Why did I use the word “absorb” in the last page? Because you could have used jj absorb. Try it:

jj undo
jj edit kk

Then run:

jj absorb README.md
Absorbed changes into 1 revisions:
  rxwzvtlz 458df236 Scaffold application

jj absorb accomplishes the same you did manually: it identifies the source of the typo (rx) and moves the edit there, automatically.

If you don’t specify a file, jj absorb analyzes all your edits. For each one, it finds the closest ancestor it can safely land in. Got multiple edits across multiple files? No problem. jj absorb dispatches each to its rightful historical Change.

If you are anything like me, you’re probably grumbling: “no way this works without breaking something”. I swear I thought the same, and I swear that Jujutsu proved me wrong.

Is it safe?

First, you always have jj undo.
Second, yes: jj absorb is highly conservative. If the destination Change is ambiguous, it does nothing rather than risk a mess.

When Do You Use It?

Whenever you find a typo or an urelated change.
But also, remember the Megamerge Workflow from Intermezzo? That’s where jj absorb shines.

The idea is: you have multiple Pull Requests waiting to be merged.

○
○
│ ○
│ ○
├─╯
│ ○
│ ○
├─╯
○
◆

As you receive feedback, rather than jumping between branches, you create an octopus merge of all your PRs, the megamerge, and sit on a new empty Change on top of it:

@       <- Your staging area
○       <- The megamerge
├─┬─╮
│ │ ○
│ │ ○
│ ○ │
│ ○ │
│ ├─╯
○ │
○ │
├─╯
○
◆

This lets you work on all your branches from a single staging area. You code directly on top of the megamerge, then you use jj absorb to dispatch each change to its proper branch, automatically.

You won’t worry about merge conflicts because:

  • jj absorb aborts rather than creating one.
  • The megamerge already proves your PRs integrate smoothly; conflicts are caught early by design.

You can read more about this workflow here: