Merge branch 'jk/fewer-pack-rescan'
[git/git.git] / Documentation / git-update-index.txt
1 git-update-index(1)
2 ===================
5 ----
6 git-update-index - Register file contents in the working tree to the index
10 --------
11 [verse]
12 'git update-index'
13 [--add] [--remove | --force-remove] [--replace]
14 [--refresh] [-q] [--unmerged] [--ignore-missing]
15 [(--cacheinfo <mode>,<object>,<file>)...]
16 [--chmod=(+|-)x]
17 [--[no-]assume-unchanged]
18 [--[no-]skip-worktree]
19 [--[no-]fsmonitor-valid]
20 [--ignore-submodules]
21 [--[no-]split-index]
22 [--[no-|test-|force-]untracked-cache]
23 [--[no-]fsmonitor]
24 [--really-refresh] [--unresolve] [--again | -g]
25 [--info-only] [--index-info]
26 [-z] [--stdin] [--index-version <n>]
27 [--verbose]
28 [--] [<file>...]
31 -----------
32 Modifies the index or directory cache. Each file mentioned is updated
33 into the index and any 'unmerged' or 'needs updating' state is
34 cleared.
36 See also linkgit:git-add[1] for a more user-friendly way to do some of
37 the most common operations on the index.
39 The way 'git update-index' handles files it is told about can be modified
40 using the various options:
43 -------
44 --add::
45 If a specified file isn't in the index already then it's
46 added.
47 Default behaviour is to ignore new files.
49 --remove::
50 If a specified file is in the index but is missing then it's
51 removed.
52 Default behavior is to ignore removed file.
54 --refresh::
55 Looks at the current index and checks to see if merges or
56 updates are needed by checking stat() information.
58 -q::
59 Quiet. If --refresh finds that the index needs an update, the
60 default behavior is to error out. This option makes
61 'git update-index' continue anyway.
63 --ignore-submodules::
64 Do not try to update submodules. This option is only respected
65 when passed before --refresh.
67 --unmerged::
68 If --refresh finds unmerged changes in the index, the default
69 behavior is to error out. This option makes 'git update-index'
70 continue anyway.
72 --ignore-missing::
73 Ignores missing files during a --refresh
75 --cacheinfo <mode>,<object>,<path>::
76 --cacheinfo <mode> <object> <path>::
77 Directly insert the specified info into the index. For
78 backward compatibility, you can also give these three
79 arguments as three separate parameters, but new users are
80 encouraged to use a single-parameter form.
82 --index-info::
83 Read index information from stdin.
85 --chmod=(+|-)x::
86 Set the execute permissions on the updated files.
88 --[no-]assume-unchanged::
89 When this flag is specified, the object names recorded
90 for the paths are not updated. Instead, this option
91 sets/unsets the "assume unchanged" bit for the
92 paths. When the "assume unchanged" bit is on, the user
93 promises not to change the file and allows Git to assume
94 that the working tree file matches what is recorded in
95 the index. If you want to change the working tree file,
96 you need to unset the bit to tell Git. This is
97 sometimes helpful when working with a big project on a
98 filesystem that has very slow lstat(2) system call
99 (e.g. cifs).
100 +
101 Git will fail (gracefully) in case it needs to modify this file
102 in the index e.g. when merging in a commit;
103 thus, in case the assumed-untracked file is changed upstream,
104 you will need to handle the situation manually.
106 --really-refresh::
107 Like `--refresh`, but checks stat information unconditionally,
108 without regard to the "assume unchanged" setting.
110 --[no-]skip-worktree::
111 When one of these flags is specified, the object name recorded
112 for the paths are not updated. Instead, these options
113 set and unset the "skip-worktree" bit for the paths. See
114 section "Skip-worktree bit" below for more information.
116 --[no-]fsmonitor-valid::
117 When one of these flags is specified, the object name recorded
118 for the paths are not updated. Instead, these options
119 set and unset the "fsmonitor valid" bit for the paths. See
120 section "File System Monitor" below for more information.
122 -g::
123 --again::
124 Runs 'git update-index' itself on the paths whose index
125 entries are different from those from the `HEAD` commit.
127 --unresolve::
128 Restores the 'unmerged' or 'needs updating' state of a
129 file during a merge if it was cleared by accident.
131 --info-only::
132 Do not create objects in the object database for all
133 <file> arguments that follow this flag; just insert
134 their object IDs into the index.
136 --force-remove::
137 Remove the file from the index even when the working directory
138 still has such a file. (Implies --remove.)
140 --replace::
141 By default, when a file `path` exists in the index,
142 'git update-index' refuses an attempt to add `path/file`.
143 Similarly if a file `path/file` exists, a file `path`
144 cannot be added. With --replace flag, existing entries
145 that conflict with the entry being added are
146 automatically removed with warning messages.
148 --stdin::
149 Instead of taking list of paths from the command line,
150 read list of paths from the standard input. Paths are
151 separated by LF (i.e. one path per line) by default.
153 --verbose::
154 Report what is being added and removed from index.
156 --index-version <n>::
157 Write the resulting index out in the named on-disk format version.
158 Supported versions are 2, 3 and 4. The current default version is 2
159 or 3, depending on whether extra features are used, such as
160 `git add -N`.
161 +
162 Version 4 performs a simple pathname compression that reduces index
163 size by 30%-50% on large repositories, which results in faster load
164 time. Version 4 is relatively young (first released in 1.8.0 in
165 October 2012). Other Git implementations such as JGit and libgit2
166 may not support it yet.
168 -z::
169 Only meaningful with `--stdin` or `--index-info`; paths are
170 separated with NUL character instead of LF.
172 --split-index::
173 --no-split-index::
174 Enable or disable split index mode. If split-index mode is
175 already enabled and `--split-index` is given again, all
176 changes in $GIT_DIR/index are pushed back to the shared index
177 file.
178 +
179 These options take effect whatever the value of the `core.splitIndex`
180 configuration variable (see linkgit:git-config[1]). But a warning is
181 emitted when the change goes against the configured value, as the
182 configured value will take effect next time the index is read and this
183 will remove the intended effect of the option.
185 --untracked-cache::
186 --no-untracked-cache::
187 Enable or disable untracked cache feature. Please use
188 `--test-untracked-cache` before enabling it.
189 +
190 These options take effect whatever the value of the `core.untrackedCache`
191 configuration variable (see linkgit:git-config[1]). But a warning is
192 emitted when the change goes against the configured value, as the
193 configured value will take effect next time the index is read and this
194 will remove the intended effect of the option.
196 --test-untracked-cache::
197 Only perform tests on the working directory to make sure
198 untracked cache can be used. You have to manually enable
199 untracked cache using `--untracked-cache` or
200 `--force-untracked-cache` or the `core.untrackedCache`
201 configuration variable afterwards if you really want to use
202 it. If a test fails the exit code is 1 and a message
203 explains what is not working as needed, otherwise the exit
204 code is 0 and OK is printed.
206 --force-untracked-cache::
207 Same as `--untracked-cache`. Provided for backwards
208 compatibility with older versions of Git where
209 `--untracked-cache` used to imply `--test-untracked-cache` but
210 this option would enable the extension unconditionally.
212 --fsmonitor::
213 --no-fsmonitor::
214 Enable or disable files system monitor feature. These options
215 take effect whatever the value of the `core.fsmonitor`
216 configuration variable (see linkgit:git-config[1]). But a warning
217 is emitted when the change goes against the configured value, as
218 the configured value will take effect next time the index is
219 read and this will remove the intended effect of the option.
221 \--::
222 Do not interpret any more arguments as options.
224 <file>::
225 Files to act on.
226 Note that files beginning with '.' are discarded. This includes
227 `./file` and `dir/./file`. If you don't want this, then use
228 cleaner names.
229 The same applies to directories ending '/' and paths with '//'
231 Using --refresh
232 ---------------
233 `--refresh` does not calculate a new sha1 file or bring the index
234 up to date for mode/content changes. But what it *does* do is to
235 "re-match" the stat information of a file with the index, so that you
236 can refresh the index for a file that hasn't been changed but where
237 the stat entry is out of date.
239 For example, you'd want to do this after doing a 'git read-tree', to link
240 up the stat index details with the proper files.
242 Using --cacheinfo or --info-only
243 --------------------------------
244 `--cacheinfo` is used to register a file that is not in the
245 current working directory. This is useful for minimum-checkout
246 merging.
248 To pretend you have a file with mode and sha1 at path, say:
250 ----------------
251 $ git update-index --cacheinfo <mode>,<sha1>,<path>
252 ----------------
254 `--info-only` is used to register files without placing them in the object
255 database. This is useful for status-only repositories.
257 Both `--cacheinfo` and `--info-only` behave similarly: the index is updated
258 but the object database isn't. `--cacheinfo` is useful when the object is
259 in the database but the file isn't available locally. `--info-only` is
260 useful when the file is available, but you do not wish to update the
261 object database.
264 Using --index-info
265 ------------------
267 `--index-info` is a more powerful mechanism that lets you feed
268 multiple entry definitions from the standard input, and designed
269 specifically for scripts. It can take inputs of three formats:
271 . mode SP sha1 TAB path
272 +
273 The first format is what "git-apply --index-info"
274 reports, and used to reconstruct a partial tree
275 that is used for phony merge base tree when falling
276 back on 3-way merge.
278 . mode SP type SP sha1 TAB path
279 +
280 The second format is to stuff 'git ls-tree' output
281 into the index file.
283 . mode SP sha1 SP stage TAB path
284 +
285 This format is to put higher order stages into the
286 index file and matches 'git ls-files --stage' output.
288 To place a higher stage entry to the index, the path should
289 first be removed by feeding a mode=0 entry for the path, and
290 then feeding necessary input lines in the third format.
292 For example, starting with this index:
294 ------------
295 $ git ls-files -s
296 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 0 frotz
297 ------------
299 you can feed the following input to `--index-info`:
301 ------------
302 $ git update-index --index-info
303 0 0000000000000000000000000000000000000000 frotz
304 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz
305 100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz
306 ------------
308 The first line of the input feeds 0 as the mode to remove the
309 path; the SHA-1 does not matter as long as it is well formatted.
310 Then the second and third line feeds stage 1 and stage 2 entries
311 for that path. After the above, we would end up with this:
313 ------------
314 $ git ls-files -s
315 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz
316 100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz
317 ------------
320 Using ``assume unchanged'' bit
321 ------------------------------
323 Many operations in Git depend on your filesystem to have an
324 efficient `lstat(2)` implementation, so that `st_mtime`
325 information for working tree files can be cheaply checked to see
326 if the file contents have changed from the version recorded in
327 the index file. Unfortunately, some filesystems have
328 inefficient `lstat(2)`. If your filesystem is one of them, you
329 can set "assume unchanged" bit to paths you have not changed to
330 cause Git not to do this check. Note that setting this bit on a
331 path does not mean Git will check the contents of the file to
332 see if it has changed -- it makes Git to omit any checking and
333 assume it has *not* changed. When you make changes to working
334 tree files, you have to explicitly tell Git about it by dropping
335 "assume unchanged" bit, either before or after you modify them.
337 In order to set "assume unchanged" bit, use `--assume-unchanged`
338 option. To unset, use `--no-assume-unchanged`. To see which files
339 have the "assume unchanged" bit set, use `git ls-files -v`
340 (see linkgit:git-ls-files[1]).
342 The command looks at `core.ignorestat` configuration variable. When
343 this is true, paths updated with `git update-index paths...` and
344 paths updated with other Git commands that update both index and
345 working tree (e.g. 'git apply --index', 'git checkout-index -u',
346 and 'git read-tree -u') are automatically marked as "assume
347 unchanged". Note that "assume unchanged" bit is *not* set if
348 `git update-index --refresh` finds the working tree file matches
349 the index (use `git update-index --really-refresh` if you want
350 to mark them as "assume unchanged").
353 Examples
354 --------
355 To update and refresh only the files already checked out:
357 ----------------
358 $ git checkout-index -n -f -a && git update-index --ignore-missing --refresh
359 ----------------
361 On an inefficient filesystem with `core.ignorestat` set::
362 +
363 ------------
364 $ git update-index --really-refresh <1>
365 $ git update-index --no-assume-unchanged foo.c <2>
366 $ git diff --name-only <3>
367 $ edit foo.c
368 $ git diff --name-only <4>
369 M foo.c
370 $ git update-index foo.c <5>
371 $ git diff --name-only <6>
372 $ edit foo.c
373 $ git diff --name-only <7>
374 $ git update-index --no-assume-unchanged foo.c <8>
375 $ git diff --name-only <9>
376 M foo.c
377 ------------
378 +
379 <1> forces lstat(2) to set "assume unchanged" bits for paths that match index.
380 <2> mark the path to be edited.
381 <3> this does lstat(2) and finds index matches the path.
382 <4> this does lstat(2) and finds index does *not* match the path.
383 <5> registering the new version to index sets "assume unchanged" bit.
384 <6> and it is assumed unchanged.
385 <7> even after you edit it.
386 <8> you can tell about the change after the fact.
387 <9> now it checks with lstat(2) and finds it has been changed.
390 Skip-worktree bit
391 -----------------
393 Skip-worktree bit can be defined in one (long) sentence: When reading
394 an entry, if it is marked as skip-worktree, then Git pretends its
395 working directory version is up to date and read the index version
396 instead.
398 To elaborate, "reading" means checking for file existence, reading
399 file attributes or file content. The working directory version may be
400 present or absent. If present, its content may match against the index
401 version or not. Writing is not affected by this bit, content safety
402 is still first priority. Note that Git _can_ update working directory
403 file, that is marked skip-worktree, if it is safe to do so (i.e.
404 working directory version matches index version)
406 Although this bit looks similar to assume-unchanged bit, its goal is
407 different from assume-unchanged bit's. Skip-worktree also takes
408 precedence over assume-unchanged bit when both are set.
410 Split index
411 -----------
413 This mode is designed for repositories with very large indexes, and
414 aims at reducing the time it takes to repeatedly write these indexes.
416 In this mode, the index is split into two files, $GIT_DIR/index and
417 $GIT_DIR/sharedindex.<SHA-1>. Changes are accumulated in
418 $GIT_DIR/index, the split index, while the shared index file contains
419 all index entries and stays unchanged.
421 All changes in the split index are pushed back to the shared index
422 file when the number of entries in the split index reaches a level
423 specified by the splitIndex.maxPercentChange config variable (see
424 linkgit:git-config[1]).
426 Each time a new shared index file is created, the old shared index
427 files are deleted if their modification time is older than what is
428 specified by the splitIndex.sharedIndexExpire config variable (see
429 linkgit:git-config[1]).
431 To avoid deleting a shared index file that is still used, its
432 modification time is updated to the current time everytime a new split
433 index based on the shared index file is either created or read from.
435 Untracked cache
436 ---------------
438 This cache is meant to speed up commands that involve determining
439 untracked files such as `git status`.
441 This feature works by recording the mtime of the working tree
442 directories and then omitting reading directories and stat calls
443 against files in those directories whose mtime hasn't changed. For
444 this to work the underlying operating system and file system must
445 change the `st_mtime` field of directories if files in the directory
446 are added, modified or deleted.
448 You can test whether the filesystem supports that with the
449 `--test-untracked-cache` option. The `--untracked-cache` option used
450 to implicitly perform that test in older versions of Git, but that's
451 no longer the case.
453 If you want to enable (or disable) this feature, it is easier to use
454 the `core.untrackedCache` configuration variable (see
455 linkgit:git-config[1]) than using the `--untracked-cache` option to
456 `git update-index` in each repository, especially if you want to do so
457 across all repositories you use, because you can set the configuration
458 variable to `true` (or `false`) in your `$HOME/.gitconfig` just once
459 and have it affect all repositories you touch.
461 When the `core.untrackedCache` configuration variable is changed, the
462 untracked cache is added to or removed from the index the next time a
463 command reads the index; while when `--[no-|force-]untracked-cache`
464 are used, the untracked cache is immediately added to or removed from
465 the index.
467 File System Monitor
468 -------------------
470 This feature is intended to speed up git operations for repos that have
471 large working directories.
473 It enables git to work together with a file system monitor (see the
474 "fsmonitor-watchman" section of linkgit:githooks[5]) that can
475 inform it as to what files have been modified. This enables git to avoid
476 having to lstat() every file to find modified files.
478 When used in conjunction with the untracked cache, it can further improve
479 performance by avoiding the cost of scanning the entire working directory
480 looking for new files.
482 If you want to enable (or disable) this feature, it is easier to use
483 the `core.fsmonitor` configuration variable (see
484 linkgit:git-config[1]) than using the `--fsmonitor` option to
485 `git update-index` in each repository, especially if you want to do so
486 across all repositories you use, because you can set the configuration
487 variable to `true` (or `false`) in your `$HOME/.gitconfig` just once
488 and have it affect all repositories you touch.
490 When the `core.fsmonitor` configuration variable is changed, the
491 file system monitor is added to or removed from the index the next time
492 a command reads the index. When `--[no-]fsmonitor` are used, the file
493 system monitor is immediately added to or removed from the index.
495 Configuration
496 -------------
498 The command honors `core.filemode` configuration variable. If
499 your repository is on a filesystem whose executable bits are
500 unreliable, this should be set to 'false' (see linkgit:git-config[1]).
501 This causes the command to ignore differences in file modes recorded
502 in the index and the file mode on the filesystem if they differ only on
503 executable bit. On such an unfortunate filesystem, you may
504 need to use 'git update-index --chmod='.
506 Quite similarly, if `core.symlinks` configuration variable is set
507 to 'false' (see linkgit:git-config[1]), symbolic links are checked out
508 as plain files, and this command does not modify a recorded file mode
509 from symbolic link to regular file.
511 The command looks at `core.ignorestat` configuration variable. See
512 'Using "assume unchanged" bit' section above.
514 The command also looks at `core.trustctime` configuration variable.
515 It can be useful when the inode change time is regularly modified by
516 something outside Git (file system crawlers and backup systems use
517 ctime for marking files processed) (see linkgit:git-config[1]).
519 The untracked cache extension can be enabled by the
520 `core.untrackedCache` configuration variable (see
521 linkgit:git-config[1]).
524 --------
525 linkgit:git-config[1],
526 linkgit:git-add[1],
527 linkgit:git-ls-files[1]
529 GIT
530 ---
531 Part of the linkgit:git[1] suite