Restoring file contents
Reset your progress
Reset your progress
To reset your progress to the start of this chapter, run the following command:
curl https://s2p2.github.io/jj-for-everyone/reset.sh | bash -s restore
cd ~/jj-tutorial/repo
If you accidentally delete a file and make other changes before realizing it, jj restore can help.
For instance, Alice deletes README.md and then modifies hello.py:
rm README.md
echo ' print("In soviet Russia, world greets you!")' >> hello.py
jj show
Commit ID: 79cda7b43c273bb0597b7888b2ff9d3afee4a568 Change ID: nwstlotvuwrnxrupxnplywqvkloupnxu Author : Alice <alice@local> (2025-08-31 16:15:13) Committer: Alice <alice@local> (2025-08-31 16:15:13) (no description set) Removed regular file README.md: 1 : # jj-tutorial 2 : 3 : The file hello.py contains a script that greets the world. 4 : It can be executed with the command 'python hello.py'. 5 : Programming is fun! 6 : 7 : ## Submission 8 : 9 : Run the following command to create the submission tarball: 10 : 11 : ~~~sh 12 : tar czf submission_alice_bob.tar.gz [FILE...] 13 : ~~~ Modified regular file hello.py: 1 1: for _ in range(10): 2 2: print("Hello, world!") 3 3: print("Hallo, Welt!") 4 4: print("Bonjour, le monde!") 5: print("In soviet Russia, world greets you!")
To restore just README.md without losing other changes, run:
jj restore README.md
Commit ID: f2922ddd5ad552e1e499b461b8ed900d047cea91 Change ID: nwstlotvuwrnxrupxnplywqvkloupnxu Author : Alice <alice@local> (2025-08-31 16:15:13) Committer: Alice <alice@local> (2025-08-31 16:24:18) (no description set) Modified regular file hello.py: 1 1: for _ in range(10): 2 2: print("Hello, world!") 3 3: print("Hallo, Welt!") 4 4: print("Bonjour, le monde!") 5: print("In soviet Russia, world greets you!")
jj restore can also revert a file to its state in any commit using the --from flag. For example, to revert hello.py to a version with no translations:
jj restore --from 'description("Fix loop syntax")' hello.py
Commit ID: c72f36748528f6893316089590374efed90a4214 Change ID: nwstlotvuwrnxrupxnplywqvkloupnxu Author : Alice <alice@local> (2025-08-31 16:15:13) Committer: Alice <alice@local> (2025-08-31 16:43:32) (no description set) Modified regular file hello.py: 1 1: for _ in range(10): 2 2: print("Hello, world!") 3 : print("Hallo, Welt!") 4 : print("Bonjour, le monde!")
After making changes, commit and push them:
jj commit -m "Remove translations"
jj bookmark move main --to @-
jj git push
You now have the skills to handle most version control problems. Here's a summary of what you've learned:
jj undo: Reverts your repository to a previous state, letting you experiment without fear.jj bookmark track: Lets you work on bookmarks that only exist on the remote.- Merge Conflicts: Resolve by editing the marked files to combine the changes.
jj abandon: Deletes commits you no longer need.jj restore: Restores file contents. By default, it reverts to the parent commit, but you can use--fromto specify any commit.
You're now equipped for most daily tasks. The next level covers rewriting history—a powerful skill for creating a clean and professional commit history.
Feel free to practice these new skills before continuing. To learn more, explore commands with --help and consult the configuration guide.