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 Chunks Around

Important

You send a single line of a file back to the past.

You learned to move all edits in specific files using jj squash -f FROM -t TO FILES. Often, you need to be more selective. See this case:

jj show ym --git
    fix name: Square -> Board

diff --git a/src/App.js b/src/App.js

--- a/src/App.js
+++ b/src/App.js
...                                     ⎫
-// Main apication                      ⎬ Typo fix
+// Main application                    ⎭
...                                     ⎫
-export default function Square() {     ⎬ Goal change
+export default function Board() {      ⎭

Given the description, my goal was clearly renaming Square() to Board(). But I also mixed in a typo fix (apication -> application). The typo originated in rx.

Running:

jj squash -f ym -t rx src/App.js

is too coarse; it drags the Square() -> Board() rename into rx too. jj absorb works here, but squash provides manual control.

Interactively Select Chunks

Give --interactive / -i a try:

jj squash -f ym -t rx -i

An editor opens, letting you select which chunks to move:

[File] [Edit] [Select] [View]
( ● ) src\App.js

[●] Section 1/2
  [●] - // Main apication ⏎
  [●] + // Main application ⏎
       2 // Display a 3x3 board and let the user ⏎
       3 // play Tic Tac Toe ⏎

[ ] Section 2/2
  [ ] - ⏎
  [ ] - export default function Square() {⏎
  [ ] + ⏎
  [ ] + export default function Board() {⏎
       6   return ( ⏎
       7     <> ⏎
       8       <div className="board-row"> ⏎
             ⋮

You can use these keys:

KeyPurpose
Up / DownMove up and down
SpaceSelect a line
fFold / unfold a file
cConfirm
qQuit without confirming

Isn’t it cool? -i is also convenient to select entire files instead of typing their paths.

Building On Top Of Squash

Look at the operations at your fingertips with squash and rebase: odds are you’re already doing things you never attempted with Git.