Rebasing 2 Branches Simultaneously
Where you discover you are a Jujutsu ninja and you are not surprised at all you can rebase 2 branches in 1 shot.
On top of n we have 3 branches (I'll name them by their tip Change ID):
rt, which introduces CSS.zx, where new functionalities are.o, which contains the manual.
○ rt Minimal CSS css <- this
│ ○ zx Click alternates Xs and Os main <- this
│ ○ v Click sets an X
│ ○ s Square has state
├─╯
│ ○ o Play instructions manual <- this
│ ○ kx Play manual
├─╯
○ n Square is interactive
~
We decide to include CSS in the other 2 branches. So, your goal is to
rebase both zx and o on top of rt.
You could do this with:
jj rebase -r kx:: -o rt
followed by
jj rebase -r s:: -o rt
Would you be able to do this in 1 command?
Solution
Solution
Union set to the rescue!
jj rebase -r 'kx:: | s::' -o rt
○ zx Click alternates Xs and Os main*
○ v Click sets an X
○ s Square has state
│ ○ o Play instructions manual*
│ ○ kx Play manual
├─╯
○ rt Minimal CSS css
│ ~
├─╯
○ n Square is interactive
Rebasing multiple branches is especially handy for keeping them up to
date with trunk. Check out
rebase-all,
an alias by Steve Klabnik, you'll love it:
you just run jj rebase-all so your local work is always based on the latest main.
People invented all sorts of amazing aliases: find them at
https://github.com/jj-vcs/jj/discussions/8484.
Preview of Revsets
You should never fear a rebase: after all, you can always resort to
jj undo. Also, you can always obtain a preview of the Changes
involved in a Revset expression using log:
jj log -r 'kx:: | s::'
○ zx Click alternates Xs and Os main*
○ v Click sets an X
○ s Square has state
│
~
○ o Play instructions manual*
○ kx Play manual
│
~
Universality of Revsets
Oh, and by the way: once you have defined a Revset expression, you can use it with many commands:
- Want to delete all those Changes?
jj abandon -r 'kx:: | s::' - Want to inspect all of them?
jj show -r 'kx:: | s::' - Want to change their author?
jj metaedit -r 'kx:: | s::' --update-author "Joe Doe"
That's a general trait: Jujutsu has few building blocks, but they combine in countless ways.