just playing with tangled
1# Comparison with Git
2
3## Introduction
4
5This document attempts to describe how Jujutsu is different from Git. See
6[the Git-compatibility doc](git-compatibility.md) for information about how
7the `jj` command interoperates with Git repos. See
8[the Git command table](git-command-table.md) for a table of similar commands.
9
10
11## Overview
12
13Here is a list of conceptual differences between Jujutsu and Git, along with
14links to more details where applicable and available. There's a
15[table](git-command-table.md) explaining how to achieve various use cases.
16
17* **The working copy is automatically committed.** That results in a simpler and
18 more consistent CLI because the working copy is now treated like any other
19 commit. [Details](working-copy.md).
20* **There's no index (staging area).** Because the working copy is automatically
21 committed, an index-like concept doesn't make sense. The index is very similar
22 to an intermediate commit between `HEAD` and the working copy, so workflows
23 that depend on it can be modeled using proper commits instead. Jujutsu has
24 excellent support for moving changes between commits. [Details](#the-index).
25* **No need for branch names (but they are supported as
26 [bookmarks](glossary.md#bookmark)).** Git lets you check out a commit without
27 attaching a branch to it. It calls this state "detached HEAD". This is the
28 normal state in Jujutsu (there's actually no way -- yet, at least -- to have
29 an active branch/bookmark). However, Jujutsu keeps track of all visible heads
30 (leaves) of the commit graph, so the commits won't get lost or
31 garbage-collected.
32* **No current branch.** Git lets you check out a branch, making it the 'current
33 branch', and new commits will automatically update the branch. This is
34 necessary in Git because Git might otherwise lose track of the new commits.
35
36 Jujutsu does not have a corresponding concept of a 'current bookmark';
37 instead, you update bookmarks manually. For example, if you start work on top
38 of a commit with a bookmark, new commits are created on top of the bookmark,
39 then you issue a later command to update the bookmark.
40* **Conflicts can be committed.** No commands fail because of merge conflicts.
41 The conflicts are instead recorded in commits and you can resolve them later.
42 [Details](conflicts.md).
43* **Descendant commits are automatically rebased.** Whenever you rewrite a
44 commit (e.g. by running `jj rebase`), all its descendants commits will
45 automatically be rebased on top. Branches pointing to it will also get
46 updated, and so will the working copy if it points to any of the rebased
47 commits.
48* **Bookmarks/branches are identified by their names (across remotes).** For
49 example, if you pull from a remote that has a `main` branch, you'll get a
50 bookmark by that name in your local repo. If you then move it and push back to
51 the remote, the `main` branch on the remote will be updated.
52 [Details](bookmarks.md).
53* **The operation log replaces reflogs.** The operation log is similar to
54 reflogs, but is much more powerful. It keeps track of atomic updates to all
55 refs at once (Jujutsu thus improves on Git's per-ref history much in the same
56 way that Subversion improved on RCS's per-file history). The operation log
57 powers e.g. the undo functionality. [Details](operation-log.md)
58* **There's a single, virtual root commit.** Like Mercurial, Jujutsu has a
59 virtual commit (with a hash consisting of only zeros) called the "root commit"
60 (called the "null revision" in Mercurial). This commit is a common ancestor of
61 all commits. That removes the awkward state Git calls the "unborn branch"
62 state (which is the state a newly initialized Git repo is in), and related
63 command-line flags (e.g. `git rebase --root`, `git checkout --orphan`).
64
65
66## The index
67
68Git's ["index"](https://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified) has
69multiple roles. One role is as a cache of file system information. Jujutsu has
70something similar. Unfortunately, Git exposes the index to the user, which makes
71the CLI unnecessarily complicated (learning what the different flavors of
72`git reset` do, especially when combined with commits and/or paths, usually
73takes a while). Jujutsu, like Mercurial, doesn't make that mistake.
74
75As a Git power-user, you may think that you need the power of the index to
76commit only part of the working copy. However, Jujutsu provides commands for
77more directly achieving most use cases you're used to using Git's index for. For
78example, to create a commit from part of the changes in the working copy, you
79might be used to using `git add -p; git commit`. With Jujutsu, you'd instead
80use `jj split` to split the working-copy commit into two commits. To add more
81changes into the parent commit, which you might normally use
82`git add -p; git commit --amend` for, you can instead use `jj squash -i` to
83choose which changes to move into the parent commit, or `jj squash <file>` to
84move a specific file.