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 a Branch

Important

You rebase a branch, then you move it back.

Rebasing sparse Changes is rarely that useful. More often you’ll rebase whole branches. Revset helps here too.
If you ran jj undo previously, your tree should look like this:

@  m        ▢
○  qn       Add the CSS file **css***
○  rt       Link to CSS
│ ○  o        Play instructions **manual***         <-- move it here
│ ○  kx       Play manual
├─╯
│ ○  zx       Click alternates Xs and Os **dev***   ⎫
│ ○  v        Click sets a X                    ⎬ this  branch
│ ○  s        Square has state                  ⎭
├─╯
○  qq       Fix
~

Warning

How would you rebase the branch from s to zx on top of o?

Tip

The solution is the literal translation of the request:

jj rebase -r "s::zx" -o o

You should arrive at:

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

Alternatively, you can use --source / -s to mark the cut point for the branch you want to rebase:

jj rebase -s s -o o

Warning

How would you undo that using rebase instead of undo?

Tip

The original base of s::zx was qq, so:

jj rebase -r "s::zx" -o qq

Give yourself a pat on the back if you nailed it.