Debian Codegraph @

docs/git-experts.md

raw
1 # Jujutsu for Git experts
2
3 People who are proficient with Git often ask what benefit there is to using
4 Jujutsu. This page explains the practical advantages for Git experts, with
5 examples showing how common workflows become easier, safer, or faster with
6 Jujutsu.
7
8 ## Git can be used side-by-side in the same repository
9
10 Jujutsu and Git repositories exist in the same directory, so you can use `jj`
11 and `git` side-by-side (this is called [colocation]). If you find a situation
12 that's easier with Git, run the `git` command and return to `jj` when you're
13 done (and please [make a feature request] if there isn't one yet!).
14
15 Colocation makes migration easier because you can adopt Jujutsu for the
16 workflows it improves without losing access to the Git commands and tools you
17 already know.
18
19 [colocation]: glossary.md#colocated-repos
20 [make a feature request]: https://github.com/jj-vcs/jj/issues
21
22 ## The Git index/staging area
23
24 Jujutsu does not have an index/staging area as Git does. Because rewriting
25 commits is quick and easy, it's natural to use commits as a replacement for the
26 index.
27
28 Instead of separate commands just for interacting with the index (`git add`,
29 `git rm --cached`), the commands `jj split` and `jj squash` can be used to move
30 work-in-progress as easily as moving finished work.
31
32 ```sh
33 # Split the working copy commit into two sequential commits, putting file1 and
34 # file2 In the first commit
35 jj split file1 file2
36
37 # or interactively select which changes to split
38 jj split
39
40 # Move the changes in file3 into the parent commit
41 jj squash file3
42 # or, interactively:
43 jj squash -i
44 ```
45
46 ## Automatic and safer history editing
47
48 If you frequently amend, reorder, or squash commits, Jujutsu can often perform
49 the same operations in fewer commands.
50
51 Suppose you want to amend an older commit. With Git you might do this in three
52 steps:
53
54 ```sh
55 git add file1 file2
56 git commit --fixup abc
57 git rebase -i --autosquash
58 ```
59
60 With Jujutsu, you simply squash the changes directly into the commit you want to
61 amend. All descendants are automatically rebased on top of the amended commit:
62
63 ```sh
64 jj squash --into abc file1 file2
65 ```
66
67 ## Undo is more powerful than using the reflog
68
69 Git's reflog is powerful, but it's per-ref and can be awkward to use when
70 multiple refs and operations are involved.
71
72 Jujutsu's operation log records the state of the entire repository: Every change
73 is an operation you can inspect, and you can restore to any earlier state with
74 one command.
75
76 Common uses of the operation log:
77
78 - `jj undo` reverts the last operation in one step, without needing to figure
79 out which ref to reset. You can repeat `jj undo` to continue stepping backwards
80 in time.
81
82 - `jj op log -p` shows operations with diffs so you can inspect what happened.
83
84 - `--at-operation ID` lets you run commands as if the repository were in a
85 previous state.
86
87 ## The evolution log shows the history of a single change
88
89 The Git reflog shows how refs moved over time, but makes it difficult to see how
90 a particular commit evolved over time. Jujutsu's evolution log ("evolog") shows
91 exactly this: Each time a change is rewritten, the update is visible in the
92 evolog.
93
94 You can use the evolog to find a previous version, then `jj restore` to restore
95 the complete or partial contents to the current version.
96
97 ## `jj absorb` makes it easier to update a patch stack
98
99 When amending several commits in a stack of changes, Git requires you to run
100 `git commit --fixup <ID>` at least once for each commit before running `git
101 rebase --autosquash`.
102
103 `jj absorb` is useful when you've made small fixes in the working copy and want
104 them incorporated into recent commits. It automatically moves each change in the
105 working copy into the previous commit where that line was changed.
106
107 Use `jj absorb --interactive` to choose only some hunks to consider for
108 absorption. Any hunks that are not selected or cannot be absorbed unambiguously
109 remain in the source commit.
110
111 It doesn't solve all cases: If multiple commits in the stack modified the same
112 line as was changed in the working copy, it will not move that change. But it
113 does help the trivial cases, leaving you to decide how to squash the remaining
114 changes.