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

Important

You learn to send file edits back to the past.

Changes and Edits

A Change contains modifications (adding a class, renaming a function, etc.) which you can inspect as a diff with jj show. The manual calls them “changes”, but it’s an overloaded term: I’ll call them “edits” from now on, OK?

Finding the Source of a Typo

To narrow down the log to single files you can use the Revset function files(). For example, the history of README.md is:

jj log -r "files('README.md')"
○  kk           Displays X X **main***
~  (elided revisions)
○  rx           Scaffold application
│
~

README.md was created in rx and modified in kk. Inspect kk:

jj show kk --git
diff --git a/README.md b/README.md
index d8ce899bb8..ec822c4346 100644
--- a/README.md                            ⎫
+++ b/README.md                            │
@@ -1,3 +1,3 @@                            ⎬   changes to README.md
-# Learning Raect.js                       │
+# Learning React.js                       ⎭

diff --git a/src/App.js b/src/App.js       ⎫
index 3f8dbe3702..495f426244 100644        ⎬   changes to src/App.js
--- a/src/App.js                           ⎭

Uh oh! In kk I mixed a Javascript update in App.js with a fix to a typo in README.md. The typo was introduced in rx:

jj file show -r rx README.md
# Learning Raect.js

Following the tutorial at https://react.dev/learn/tutorial-tic-tac-toe

So, I wrote the typo in rx, missed it, found it later while coding App.js, and lazily mixed the fix into kk. How do we move the fix from kk back to rx?

Sending Fixes Back to the Past

Rebasing won’t help here: rebase moves Changes, while we want to move edits.

Enter squash. In Git squash combines multiple commits. jj squash generalizes this concept; more generally, it transfers edits from one Change to another. The basic syntax is:

jj squash --from A --into B [FILES]

or, shortly:

jj squash -f A -t B [FILES]

The net effect: the edits to [FILES] move from A to B. Your edits stay the same; only which Change owns them differs.

Warning

Help me fix the mess I made in Raect.js.

Tip

jj squash -f kk -t rx README.md

Bravo! You are basically saying: “I typed this in kk. Rewrite history so I typed it in rx.”

Check kk:

jj show --summary kk
M src\App.js

README.md is gone. In rx, the typo is fixed:

jj file show -r rx README.md
# Learning React.js

Following the tutorial at https://react.dev/learn/tutorial-tic-tac-toe

The typo fix was absorbed into the past. Next time you find a typo while working on something unrelated, fix it on the spot, then send it back where it belongs.