Debian Codegraph @

docs/working-copy.md

raw
1 # Working copy
2
3 ## Introduction
4
5 The working copy is where the current working-copy commit's files are written so
6 you can interact with them. It is also where files are read from in order to
7 create new commits (though there are many other ways of creating new commits).
8
9 Unlike most other VCSs, Jujutsu will automatically create commits from the
10 working-copy contents when they have changed. Most `jj` commands you run will
11 commit the working-copy changes if they have changed. The resulting revision
12 will replace the previous working-copy revision.
13
14 Also unlike most other VCSs, added files are implicitly tracked by default. That
15 means that if you add a new file to the working copy, it will be automatically
16 committed once you run e.g. `jj st`. Similarly, if you remove a file from the
17 working copy, it will implicitly be untracked.
18
19 The `snapshot.auto-track` config option controls which paths get automatically
20 tracked when they're added to the working copy. See the
21 [fileset documentation](filesets.md) for the syntax. Files with paths matching
22 [ignore files](#ignored-files) are never tracked automatically.
23
24 If you set `snapshot.auto-track` to a non-default value, untracked files can be
25 tracked with `jj file track`.
26
27 You can use `jj file untrack` to untrack a file while keeping it in the working
28 copy. However, first [ignore](#ignored-files) them or remove them from the
29 `snapshot.auto-track` patterns; otherwise they will be immediately tracked again.
30
31 ## Conflicts
32
33 When you check out a commit with conflicts, those conflicts need to be
34 represented in the working copy somehow. However, the file system doesn't
35 understand conflicts. Jujutsu's solution is to add conflict markers to
36 conflicted files when it writes them to the working copy. It also keeps track of
37 the (typically 3) different parts involved in the conflict. Whenever it scans
38 the working copy thereafter, it parses the conflict markers and recreates the
39 conflict state from them. You can resolve conflicts by replacing the conflict
40 markers by the resolved text. You don't need to resolve all conflicts at once.
41 You can even resolve part of a conflict by updating the different parts of the
42 conflict marker.
43
44 To resolve conflicts in a commit, use `jj new <commit>` to create a working-copy
45 commit on top. You would then have the same conflicts in the working-copy
46 commit. Once you have resolved the conflicts, you can inspect the conflict
47 resolutions with `jj diff`. Then run `jj squash` to move the conflict
48 resolutions into the conflicted commit. Alternatively, you can edit the commit
49 with conflicts directly in the working copy by using `jj edit <commit>`. The
50 main disadvantage of that is that it's harder to inspect the conflict
51 resolutions.
52
53 With the `jj resolve` command, you can use an external merge tool to resolve
54 conflicts that have 2 sides and a base. There is not yet a good way of
55 resolving conflicts between directories, files, and symlinks
56 (<https://github.com/jj-vcs/jj/issues/19>). You can use `jj restore` to choose
57 one side of the conflict, but there's no way to even see where the involved
58 parts came from.
59
60 ## Ignored files
61
62 You probably don't want build outputs and temporary files to be under version
63 control. You can tell Jujutsu to not automatically track certain files by using
64 `.gitignore` files (there's no such thing as `.jjignore` yet). See
65 <https://git-scm.com/docs/gitignore> for details about the format. `.gitignore`
66 files are supported in any directory in the working copy, as well as in
67 `$XDG_CONFIG_HOME/git/ignore` and `$GIT_DIR/info/exclude`.
68
69 Ignored files are never tracked automatically (regardless of the value of
70 `snapshot.auto-track`), but files that were already tracked will remain tracked
71 even if they match ignore patterns. You can untrack such files with the
72 `jj file untrack` command.
73
74 ## Workspaces
75
76 You can have multiple working copies backed by a single repo. Use
77 `jj workspace add` to create a new working copy. The working copy will have a
78 `.jj/` directory linked to the main repo. The working copy and the `.jj/`
79 directory together is called a "workspace". Each workspace can have a different
80 commit checked out.
81
82 Having multiple workspaces can be useful for running long-running tests in one
83 while you continue developing in another, for example. If needed,
84 `jj workspace root --name <workspace>` prints the root path of the specified
85 workspace (defaults to the current one).
86
87 `jj workspace list` shows every workspace together with its available root path.
88
89 When you're done using a workspace, use `jj workspace forget` to make the repo
90 forget about it. The files can be deleted from disk separately (either before or
91 after).
92
93 ## Stale working copy
94
95 Almost all commands go through three main steps:
96
97 1. Snapshot the working copy (which gets recorded as an operation)
98 2. Create new commits etc. "in memory" and record that as a new operation
99 3. Update the working copy to match the new operation, i.e. to the commit that
100 the operation says that `@` should point to
101
102 If step 3 doesn't happen for some reason, the working copy is considered
103 "stale". We can detect that because the working copy (`.jj/working_copy/`)
104 keeps track of which operation it was last updated to. When the working copy is
105 stale, use `jj workspace update-stale` to update the files in the working copy.
106
107 A common reason that step 3 doesn't happen for a working copy is that you
108 rewrote the commit from another workspace. When you modify workspace A's
109 working-copy commit from workspace B, workspace A's working copy will become
110 stale.
111
112 A working copy can also become stale because some error, such as `^C` prevented
113 step 3 from completing. It's also possible that it was successfully updated in
114 step 3 but the operation has then been lost (e.g. by `jj op abandon` or
115 "spontaneously" by certain storage backends). If the operation has been lost,
116 then `jj workspace update-stale` will create a recovery commit with the
117 contents of the working copy but parented to the current operation's
118 working-copy commit.