Restarting
The jj restore --help page states:
When neither
--fromnor--intois specified, the command restores into the working copy from its parent(s).
That's a neat default! It means that:
jj restore
is equivalent to:
jj restore -f @- -t @ .
which makes the Current Change identical to its parent. It's a convenient way to clean up everything and start over.
Give it a try:
○ rt Link to CSS
○ n Square is interactive
○ ru Board() invokes Square()
├─╮
○ │ ym Rename: Square -> Board
○ │ xx WIP delete me
○ │ yz LICENSE
○ │ ws A board full of X
├─╯
○ kk Displays X X
○ wx Fails
○ rx Scaffold application
Select any Change you like (say: ru) and create a new Change on
top of it:
jj new ru
Make any modification you like:
$ touch unnecessary.txt
$ echo "a bug" >> src/App.js
$ rm src/index.js
$ jj st
Working copy changes:
M public/index.html
M src/App.js
D src/index.js
A unnecessary.txt
2 modified files, 1 deleted and 1 added.
How to start over and get back to an empty Change?
Solution
Solution
But it's trivial!
$ jj restore
Added 1 files, modified 2 files, removed 1 files
$ jj st
The working copy has no changes.
Back to the start.
Isn't This equivalent to git restore?
Not really. In Git, the same information is spread across three
layers, HEAD, the Index, and the working tree, plus the fourth grey
area of untracked files. As a result, you need different commands and
options depending on which subset you want to affect.
| Goal | Git |
|---|---|
| Discard unstaged changes | git restore . |
| Discard both staged and unstaged changes | git restore --staged --worktree . or git reset --hard HEAD |
Clean restart, equivalent to jj restore | git reset --hard HEAD && git clean -fd |
Nuclear cleanup (including .gitignored files) | git reset --hard HEAD && git clean -fdx |