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

You learn a new workflow which might look both:

  • Exotic: you would commit before coding!
  • And familiar: you won't miss the Git index anymore.

The Squash Workflow

Apparently, this is the preferred workflow by Martin von Zweigbergk, the guy who invented Jujutsu. So it is probably deeply rooted in Jujutsu's philosophy.

It revolves around these 2 ideas:

  • You start by committing.
  • Then, you code in a disposable Change on top of your commit.

When you are done with your work, you squash down the changes. Let me just show you; it's faster than explaining.

$ jj log

○  q    Add the CSS file css
○  rt   Link to CSS
│ ○  o  Play instructions manual
│ ○  kx Play manual
├─╯
│ ○  zx Click alternates Xs and Os main
│ ○  v  Click sets a X
│ ○  s  Square has state
├─╯
○  n    Square is interactive
~

The Changes rt and q are about the CSS. Let's say that you want to improve the web page layout, adding a mouse hover effect.

First: Commit!

You start by declaring your intent, committing to a goal:

$ jj new -r q -m "Hover effect to board squares"

○  rt   empty Hover effect to board squares
○  q    Add the CSS file css
○  rt   Link to CSS
~

You haven't started coding yet, so of course the Change is empty. Eventually, it will be the next commit in your history. Think of the Git index, it's pretty much the same idea: a Candidate Commit.

Second: Set Up Your Workspace

Then build a disposable Change on top of your Candidate Commit:

$ jj new

○  xm   empty
○  rt   empty Hover effect to board squares
○  q    Add the CSS file css
○  rt   Link to CSS
~

That empty, messageless Change may seem odd, but squint a little, it's just like Git. With Git you start with:

In GitIn Jujutsu
An empty Index, the Candidate Commit.This is your rt Change.
A working directory with no pending changes.This is equivalent to your empty, Current Change xm.

Third: You Code

Nothing new to see here: Jujutsu reflects every file system change in your tip Change xm.

Finally: You Squash

When you're done, review and move your changes back to the Candidate Commit.

jj squash

or:

jj squash -i

if you want to do this chunk by chunk.

When jj squash completes, the now-empty tip Change is automatically abandoned and replaced with a fresh one.

Try It Out

Give it a try. Say you want to add:

.square:hover {
  background: #e0f7fa;
  cursor: pointer;
  transition: background 0.2s;
}

to style.css. Your turn!

Solution

Most of the work is already done! The Candidate Commit is already there. You just need to do the funniest part (coding! 😎).
Then:

jj squash -i

or just jj squash.