Debian Codegraph @

docs/git-comparison.md

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