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

Goal

In which you start believing in magic.

Dispatching Edits from Megamerges

Why did I say "absorb" in the previous chapter? Because you could have done that squash using jj absorb. Run a jj undo and give it a try. Go to kk:

jj edit kk

and run:

jj absorb README.md

jj absorb will accomplish what you just did manually: it will identify the source of the typo and will move the edit there.

If you don't specify the file, jj absorb will analyze all the edits you did. For each individual edit, it will figure out the closest ancestor it can safely land in. Got multiple edits across multiple files? No problem: jj absorb will split them apart and dispatch each one to its rightful Change back in your history.

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 of all, you always have jj undo.
Besides this, yes, it is: jj absorb is very conservative: when the destination Change can't be unambiguously determined, jj absorb does nothing rather than risk a mess.

When Do You Use It?

Remember the Megamerge Workflow I told you about in Intermezzo: A Taste Of a Fanciful Workflow? That's the typical case where jj absorb shines.

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

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

and over time you receive feedbacks on them. Rather than jumping left and right to fine-tune your code, you create an octopus merge of all your PRs, the megamerge, and you sit on top of it, in a new empty Change:

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

This lets you work on all your branches from a single staging area.

How does it work? As feedback comes in on one of your Pull Requests, you make the necessary change directly on top of the megamerge, which contains the sum of all your work; then you use jj absorb to dispatch the change where it belongs.

You won't have to worry about merge conflicts, because:

  • jj absorb would stop rather than creating one.
  • The megamerge already proves all your PRs work together, so conflicts are caught early by design.

You can read more about this workflow in the following two articles. There's a video in the first one if you want to see how this works in practice.