| 1 |
# Comparison with Sapling |
| 2 |
|
| 3 |
## Introduction |
| 4 |
|
| 5 |
This document attempts to describe how jj is different |
| 6 |
from [Sapling](https://sapling-scm.com). Sapling is a VCS developed by Meta. It |
| 7 |
was announced about 3 years after development started on jj. It is a heavily |
| 8 |
modified fork of [Mercurial](https://www.mercurial-scm.org/). Because jj has |
| 9 |
copied many ideas from Mercurial, there are many similarities between the two |
| 10 |
tools, such as: |
| 11 |
|
| 12 |
* A user-friendly CLI |
| 13 |
* A "[revset](revsets.md)" language for selecting revisions |
| 14 |
* Good support for working with stacked commits, including tracking "anonymous |
| 15 |
heads" (no "detached HEAD" state like in Git) and `split` commands, and |
| 16 |
automatically rebasing descendant commits when you amend a commit. |
| 17 |
* Flexible customization of output using [templates](templates.md) |
| 18 |
|
| 19 |
## Differences |
| 20 |
|
| 21 |
Here is a list of some differences between jj and Sapling. |
| 22 |
|
| 23 |
* **Working copy:** When using Sapling (like most VCSs), the |
| 24 |
user explicitly tells the tool when to create a commit and which files to |
| 25 |
include. When using jj, the working copy |
| 26 |
is [automatically snapshotted by every command](working-copy.md). New files |
| 27 |
are automatically tracked and deleted files are automatically untracked. This |
| 28 |
has several advantages: |
| 29 |
|
| 30 |
* The working copy is effectively backed up every time you run a command. |
| 31 |
* No commands fail because you have changes in the working copy ("abort: 1 |
| 32 |
conflicting file changes: ..."). No need for `sl shelve`. |
| 33 |
* Simpler and more consistent CLI because the working copy is treated like any |
| 34 |
other commit. |
| 35 |
|
| 36 |
* **Conflicts:** Like most VCSs, Sapling requires the user to |
| 37 |
resolve conflicts before committing. jj lets |
| 38 |
you [commit conflicts](conflicts.md). Note that it's a representation of the |
| 39 |
conflict that's committed, not conflict markers (`<<<<<<<` etc.). This also |
| 40 |
has several advantages: |
| 41 |
|
| 42 |
* Merge conflicts won't prevent you from checking out another commit. |
| 43 |
* You can resolve the conflicts when you feel like it. |
| 44 |
* Rebasing descendants always succeeds. Like jj, Sapling automatically |
| 45 |
rebases, but it will fail if there are conflicts. |
| 46 |
* Merge commits can be rebased correctly (Sapling sometimes fails). |
| 47 |
* You can rebase conflicts and conflict resolutions. |
| 48 |
|
| 49 |
* **Undo:** jj's undo is powered by [the operation log](operation-log.md), which |
| 50 |
records how the repo has changed over time. Sapling has a similar feature |
| 51 |
with its [MetaLog](https://sapling-scm.com/docs/internals/metalog). |
| 52 |
They seem to provide similar functionality, but jj also exposes the log to the |
| 53 |
user via `jj op log`, so you can tell how far back you want to go back. |
| 54 |
Sapling has `sl debugmetalog`, but that seems to show the history of a single |
| 55 |
commit, not the whole repo's history. Thanks to jj snapshotting the working |
| 56 |
copy, it's possible to undo changes to the working copy. For example, if |
| 57 |
you `jj undo` a ` jj commit`, `jj diff` will show the same changes as |
| 58 |
before `jj commit`, but if you `sl undo` a `sl commit`, the working copy will |
| 59 |
be clean. |
| 60 |
* **Git interop:** Sapling supports cloning, pushing, and pulling from a remote |
| 61 |
Git repo. jj also does, and it also supports sharing a working copy with a Git |
| 62 |
repo, so you can use `jj` and `git` interchangeably in the same repo. |
| 63 |
* **Polish:** Sapling is more polished and feature-complete. Sapling has very |
| 64 |
nice built-in web UI called |
| 65 |
[Interactive Smartlog](https://sapling-scm.com/docs/addons/isl), which lets |
| 66 |
you drag and drop commits to rebase them, among other things. |
| 67 |
* **Forge workflow:** Sapling has `sl pr submit --stack`, which lets you |
| 68 |
push a stack of commits as separate GitHub PRs, including setting the base |
| 69 |
branch. It only supports GitHub. jj doesn't have any direct integration with |
| 70 |
GitHub or any other forge. However, it has `jj git push --change` for |
| 71 |
automatically creating branches for specified commits. You have to specify |
| 72 |
each commit you want to create a branch for by using |
| 73 |
`jj git push --change X --change Y ...`, and you have to manually set up any |
| 74 |
base branches in GitHub's UI (or GitLab's or ...). On subsequent pushes, you |
| 75 |
can update all at once by specifying something like `jj git push -r main..@` |
| 76 |
(to push all branches on the current stack of commits from where it forked |
| 77 |
from `main`). |