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

Rebasing 2 Branches Simultaneously

Important

In you which you discover you’re a Jujutsu ninja: rebasing 2 branches at once won’t even surprise you.

By now you may have guessed that a single Revset expression can describe more than one branch.

On top of qq we have 3 branches, css, manual and dev:

○  qn       Add the CSS file **css***
○  rt       Link to CSS
│ ○  o        Play instructions **manual***
│ ○  kx       Play manual
├─╯
│ ○  zx       Click alternates Xs and Os **dev***
│ ○  v        Click sets a X
│ ○  s        Square has state
├─╯
○  qq       Fix
~

Your goal is to rebase both dev and manual on top of css. You could do this sequentially:

jj rebase -r kx:: -o qn
jj rebase -r s:: -o qn

Warning

Could you do this in 1 command?

Tip

Union Revset to the rescue!

jj rebase -r 'kx:: | s::' -o qn
○  o        Play instructions **manual***
○  kx       Play manual
│
│ ○  zx       Click alternates Xs and Os **dev***
│ ○  v        Click sets a X
│ ○  s        Square has state
├─╯
○  qn       Add the CSS file **css***
○  rt       Link to CSS
○  qq       Fix

Rebasing multiple branches is handy for keeping them updated with trunk. Check out rebase-all, an alias by Steve Klabnik: just run jj rebase-all to rebase your local work onto the latest main.

People invented all sorts of amazing aliases: find them at https://github.com/jj-vcs/jj/discussions/8484.

Preview of Revsets

Never fear a rebase: jj undo has your back. Plus, you can preview any Revset with jj log before applying it:

jj log -r 'kx:: | s::'
○  zx       Click alternates Xs and Os main*
○  v        Click sets an X
○  s        Square has state
│
~

○  o        Play instructions
○  kx       Play manual
│
~

Universality of Revsets

Further more! Once you define a Revset like kx:: | s::, you can use it anywhere:

  • Delete those Changes? jj abandon -r 'kx:: | s::'
  • Inspect them? jj show -r 'kx:: | s::'
  • Change their author? jj metaedit -r 'kx:: | s::' --update-author "Joe Doe"

This never stops amazing me: Jujutsu’s has few building blocks, but they combine in countless ways.