Copying Files
Important
Your learn to copy/paste files from one Change to another.
Good things come in threes. You’ve met jj squash and jj rebase;
meet jj restore. Together, these three musketeers bend the history
tree to your will:
| Operation | Command |
|---|---|
| Move a Change | rebase |
| Move your edits | squash |
| Copy files from one Change to another | restore |
jj restore is similar to Bash’s cp: it copies file contents. It
uses the same syntax as jj squash (how many times did I tell you
Jujutsu is beautifully consistent?):
jj restore -f FROM -t TO FILES
This copies FILES from FROM to TO. The original in FROM
remains unmodified.
If a file was deleted in FROM, it gets deleted in TO as well.
Like squash, omitting -f or -t implies the Current Change @.
Omitting FILES restores the entire working copy.
When Is It Useful?
Days ago, your README.md had rich examples and beautiful ASCII
diagrams. Then your PM asked for something “more executive”. Fine, you
trimmed it down. PMs are always right. Especially on Friday
afternoon.
Today the same PM says (because of course they do): “You know what? Actually, I liked the long version better”.
You sigh and call jj restore to the rescue:
- Find the old Change
X(docs: README with beautiful diagrams). - Run
jj restore --from X README.md
Done.
You aren’t going back in time: instead, you pulled a file out of an
old snapshot and pasted it into your Current Change.
Is This Common?
You won’t do it every day, but just like jj squash, jj restore’s
default arguments lead to very interesting consequences. Let’s see
in the next page.