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

Moving Changes

Important

You discover that rebasing isn’t just moving a branch to a different base.
You can insert a single Change right in the middle of the history tree.

jj rebase works by specifying:

  • Which Changes you want to move (-r).
  • Where you want to move them (--onto, --before or --after, same options of jj new).

So:

jj rebase -r X -o Y

moves X on top of Y.

The sample repository is full of mistakes and unfinished work. Let’s fix them.

First, the License

Oh, no! I added the license too late, in Change yz:

~
├─╮
○ │  ym       fix name: Square -> Board
○ │  x        WIP delete me
○ │  yz       LICENSE                      <-- here
○ │  ws       A board full of X
├─╯
○  kk       Displays X X **main**
○  wx       Fails
○  rx       Scaffold applicatio
◆  zz   🔒  empty                          <-- should have been right after root()
jj show --summary yz
  A LICENSE

Ideally, the license should be the very first commit. Somehow, yz ended up stranded in a merged branch.

Warning

Can you move yz so it becomes the initial commit?

Tip

jj rebase -r yz -A zz

or:

jj rebase -r yz -B rx

Things Committed by Mistake

Talking about that branch, its Change x has the suspicious message WIP: delete me.

Warning

What does it contain?

Tip

jj show x --summary
A node_modules/yaml/LICENSE
A node_modules/yaml/index.js

Ouch! I committed node_modules

Warning

How do you get rid of it?

Tip

jj abandon x

And x is gone.

Why this exercise? Because under the hood, while abandoning, Jujutsu did move Changes: it rebased x’s descendants onto yz. Moving things doesn’t always look like moving things: Jujutsu commands capture your intent, not the underlying mechanics.

Typos

Notice the typo in rx’s message: applicatio instead of application.

Warning

How would you fix it?

Tip

jj desc -r rx -m "Scaffold application"
Rebased 13 descendant commits
Working copy  (@) now at: xxuknwml 770ae789 WIP delete me
Parent commit (@-)      : yzxvwmnz 02b946ad LICENSE

Again: your intent was editing a message, but the log (Rebased 13 descendant commits) reveals it’s still about moving Changes.

Let’s look at cases where your explicit intent is actually moving Changes.