1GIT-UPDATE-INDEX(1) Git Manual GIT-UPDATE-INDEX(1)
2
3
4
6 git-update-index - Register file contents in the working tree to the
7 index
8
10 git update-index
11 [--add] [--remove | --force-remove] [--replace]
12 [--refresh] [-q] [--unmerged] [--ignore-missing]
13 [(--cacheinfo <mode>,<object>,<file>)...]
14 [--chmod=(+|-)x]
15 [--[no-]assume-unchanged]
16 [--[no-]skip-worktree]
17 [--[no-]ignore-skip-worktree-entries]
18 [--[no-]fsmonitor-valid]
19 [--ignore-submodules]
20 [--[no-]split-index]
21 [--[no-|test-|force-]untracked-cache]
22 [--[no-]fsmonitor]
23 [--really-refresh] [--unresolve] [--again | -g]
24 [--info-only] [--index-info]
25 [-z] [--stdin] [--index-version <n>]
26 [--verbose]
27 [--] [<file>...]
28
30 Modifies the index. Each file mentioned is updated into the index and
31 any unmerged or needs updating state is cleared.
32
33 See also git-add(1) for a more user-friendly way to do some of the most
34 common operations on the index.
35
36 The way git update-index handles files it is told about can be modified
37 using the various options:
38
40 --add
41 If a specified file isn’t in the index already then it’s added.
42 Default behaviour is to ignore new files.
43
44 --remove
45 If a specified file is in the index but is missing then it’s
46 removed. Default behavior is to ignore removed file.
47
48 --refresh
49 Looks at the current index and checks to see if merges or updates
50 are needed by checking stat() information.
51
52 -q
53 Quiet. If --refresh finds that the index needs an update, the
54 default behavior is to error out. This option makes git
55 update-index continue anyway.
56
57 --ignore-submodules
58 Do not try to update submodules. This option is only respected when
59 passed before --refresh.
60
61 --unmerged
62 If --refresh finds unmerged changes in the index, the default
63 behavior is to error out. This option makes git update-index
64 continue anyway.
65
66 --ignore-missing
67 Ignores missing files during a --refresh
68
69 --cacheinfo <mode>,<object>,<path>, --cacheinfo <mode> <object> <path>
70 Directly insert the specified info into the index. For backward
71 compatibility, you can also give these three arguments as three
72 separate parameters, but new users are encouraged to use a
73 single-parameter form.
74
75 --index-info
76 Read index information from stdin.
77
78 --chmod=(+|-)x
79 Set the execute permissions on the updated files.
80
81 --[no-]assume-unchanged
82 When this flag is specified, the object names recorded for the
83 paths are not updated. Instead, this option sets/unsets the "assume
84 unchanged" bit for the paths. When the "assume unchanged" bit is
85 on, the user promises not to change the file and allows Git to
86 assume that the working tree file matches what is recorded in the
87 index. If you want to change the working tree file, you need to
88 unset the bit to tell Git. This is sometimes helpful when working
89 with a big project on a filesystem that has very slow lstat(2)
90 system call (e.g. cifs).
91
92 Git will fail (gracefully) in case it needs to modify this file in
93 the index e.g. when merging in a commit; thus, in case the
94 assumed-untracked file is changed upstream, you will need to handle
95 the situation manually.
96
97 --really-refresh
98 Like --refresh, but checks stat information unconditionally,
99 without regard to the "assume unchanged" setting.
100
101 --[no-]skip-worktree
102 When one of these flags is specified, the object name recorded for
103 the paths are not updated. Instead, these options set and unset the
104 "skip-worktree" bit for the paths. See section "Skip-worktree bit"
105 below for more information.
106
107 --[no-]ignore-skip-worktree-entries
108 Do not remove skip-worktree (AKA "index-only") entries even when
109 the --remove option was specified.
110
111 --[no-]fsmonitor-valid
112 When one of these flags is specified, the object name recorded for
113 the paths are not updated. Instead, these options set and unset the
114 "fsmonitor valid" bit for the paths. See section "File System
115 Monitor" below for more information.
116
117 -g, --again
118 Runs git update-index itself on the paths whose index entries are
119 different from those from the HEAD commit.
120
121 --unresolve
122 Restores the unmerged or needs updating state of a file during a
123 merge if it was cleared by accident.
124
125 --info-only
126 Do not create objects in the object database for all <file>
127 arguments that follow this flag; just insert their object IDs into
128 the index.
129
130 --force-remove
131 Remove the file from the index even when the working directory
132 still has such a file. (Implies --remove.)
133
134 --replace
135 By default, when a file path exists in the index, git update-index
136 refuses an attempt to add path/file. Similarly if a file path/file
137 exists, a file path cannot be added. With --replace flag, existing
138 entries that conflict with the entry being added are automatically
139 removed with warning messages.
140
141 --stdin
142 Instead of taking list of paths from the command line, read list of
143 paths from the standard input. Paths are separated by LF (i.e. one
144 path per line) by default.
145
146 --verbose
147 Report what is being added and removed from index.
148
149 --index-version <n>
150 Write the resulting index out in the named on-disk format version.
151 Supported versions are 2, 3 and 4. The current default version is 2
152 or 3, depending on whether extra features are used, such as git add
153 -N.
154
155 Version 4 performs a simple pathname compression that reduces index
156 size by 30%-50% on large repositories, which results in faster load
157 time. Version 4 is relatively young (first released in 1.8.0 in
158 October 2012). Other Git implementations such as JGit and libgit2
159 may not support it yet.
160
161 -z
162 Only meaningful with --stdin or --index-info; paths are separated
163 with NUL character instead of LF.
164
165 --split-index, --no-split-index
166 Enable or disable split index mode. If split-index mode is already
167 enabled and --split-index is given again, all changes in
168 $GIT_DIR/index are pushed back to the shared index file.
169
170 These options take effect whatever the value of the core.splitIndex
171 configuration variable (see git-config(1)). But a warning is
172 emitted when the change goes against the configured value, as the
173 configured value will take effect next time the index is read and
174 this will remove the intended effect of the option.
175
176 --untracked-cache, --no-untracked-cache
177 Enable or disable untracked cache feature. Please use
178 --test-untracked-cache before enabling it.
179
180 These options take effect whatever the value of the
181 core.untrackedCache configuration variable (see git-config(1)). But
182 a warning is emitted when the change goes against the configured
183 value, as the configured value will take effect next time the index
184 is read and this will remove the intended effect of the option.
185
186 --test-untracked-cache
187 Only perform tests on the working directory to make sure untracked
188 cache can be used. You have to manually enable untracked cache
189 using --untracked-cache or --force-untracked-cache or the
190 core.untrackedCache configuration variable afterwards if you really
191 want to use it. If a test fails the exit code is 1 and a message
192 explains what is not working as needed, otherwise the exit code is
193 0 and OK is printed.
194
195 --force-untracked-cache
196 Same as --untracked-cache. Provided for backwards compatibility
197 with older versions of Git where --untracked-cache used to imply
198 --test-untracked-cache but this option would enable the extension
199 unconditionally.
200
201 --fsmonitor, --no-fsmonitor
202 Enable or disable files system monitor feature. These options take
203 effect whatever the value of the core.fsmonitor configuration
204 variable (see git-config(1)). But a warning is emitted when the
205 change goes against the configured value, as the configured value
206 will take effect next time the index is read and this will remove
207 the intended effect of the option.
208
209 --
210 Do not interpret any more arguments as options.
211
212 <file>
213 Files to act on. Note that files beginning with . are discarded.
214 This includes ./file and dir/./file. If you don’t want this, then
215 use cleaner names. The same applies to directories ending / and
216 paths with //
217
219 --refresh does not calculate a new sha1 file or bring the index up to
220 date for mode/content changes. But what it does do is to "re-match" the
221 stat information of a file with the index, so that you can refresh the
222 index for a file that hasn’t been changed but where the stat entry is
223 out of date.
224
225 For example, you’d want to do this after doing a git read-tree, to link
226 up the stat index details with the proper files.
227
229 --cacheinfo is used to register a file that is not in the current
230 working directory. This is useful for minimum-checkout merging.
231
232 To pretend you have a file at path with mode and sha1, say:
233
234 $ git update-index --add --cacheinfo <mode>,<sha1>,<path>
235
236 --info-only is used to register files without placing them in the
237 object database. This is useful for status-only repositories.
238
239 Both --cacheinfo and --info-only behave similarly: the index is updated
240 but the object database isn’t. --cacheinfo is useful when the object is
241 in the database but the file isn’t available locally. --info-only is
242 useful when the file is available, but you do not wish to update the
243 object database.
244
246 --index-info is a more powerful mechanism that lets you feed multiple
247 entry definitions from the standard input, and designed specifically
248 for scripts. It can take inputs of three formats:
249
250 1. mode SP type SP sha1 TAB path
251
252 This format is to stuff git ls-tree output into the index.
253
254 2. mode SP sha1 SP stage TAB path
255
256 This format is to put higher order stages into the index file and
257 matches git ls-files --stage output.
258
259 3. mode SP sha1 TAB path
260
261 This format is no longer produced by any Git command, but is and
262 will continue to be supported by update-index --index-info.
263
264 To place a higher stage entry to the index, the path should first be
265 removed by feeding a mode=0 entry for the path, and then feeding
266 necessary input lines in the third format.
267
268 For example, starting with this index:
269
270 $ git ls-files -s
271 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 0 frotz
272
273 you can feed the following input to --index-info:
274
275 $ git update-index --index-info
276 0 0000000000000000000000000000000000000000 frotz
277 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz
278 100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz
279
280 The first line of the input feeds 0 as the mode to remove the path; the
281 SHA-1 does not matter as long as it is well formatted. Then the second
282 and third line feeds stage 1 and stage 2 entries for that path. After
283 the above, we would end up with this:
284
285 $ git ls-files -s
286 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz
287 100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz
288
290 Many operations in Git depend on your filesystem to have an efficient
291 lstat(2) implementation, so that st_mtime information for working tree
292 files can be cheaply checked to see if the file contents have changed
293 from the version recorded in the index file. Unfortunately, some
294 filesystems have inefficient lstat(2). If your filesystem is one of
295 them, you can set "assume unchanged" bit to paths you have not changed
296 to cause Git not to do this check. Note that setting this bit on a path
297 does not mean Git will check the contents of the file to see if it has
298 changed — it makes Git to omit any checking and assume it has not
299 changed. When you make changes to working tree files, you have to
300 explicitly tell Git about it by dropping "assume unchanged" bit, either
301 before or after you modify them.
302
303 In order to set "assume unchanged" bit, use --assume-unchanged option.
304 To unset, use --no-assume-unchanged. To see which files have the
305 "assume unchanged" bit set, use git ls-files -v (see git-ls-files(1)).
306
307 The command looks at core.ignorestat configuration variable. When this
308 is true, paths updated with git update-index paths... and paths updated
309 with other Git commands that update both index and working tree (e.g.
310 git apply --index, git checkout-index -u, and git read-tree -u) are
311 automatically marked as "assume unchanged". Note that "assume
312 unchanged" bit is not set if git update-index --refresh finds the
313 working tree file matches the index (use git update-index
314 --really-refresh if you want to mark them as "assume unchanged").
315
316 Sometimes users confuse the assume-unchanged bit with the skip-worktree
317 bit. See the final paragraph in the "Skip-worktree bit" section below
318 for an explanation of the differences.
319
321 To update and refresh only the files already checked out:
322
323 $ git checkout-index -n -f -a && git update-index --ignore-missing --refresh
324
325 On an inefficient filesystem with core.ignorestat set
326
327 $ git update-index --really-refresh [1m(1)
328 $ git update-index --no-assume-unchanged foo.c [1m(2)
329 $ git diff --name-only [1m(3)
330 $ edit foo.c
331 $ git diff --name-only [1m(4)
332 M foo.c
333 $ git update-index foo.c [1m(5)
334 $ git diff --name-only [1m(6)
335 $ edit foo.c
336 $ git diff --name-only [1m(7)
337 $ git update-index --no-assume-unchanged foo.c [1m(8)
338 $ git diff --name-only [1m(9)
339 M foo.c
340
341 1. forces lstat(2) to set "assume unchanged" bits for paths
342 that match index.
343 2. mark the path to be edited.
344 3. this does lstat(2) and finds index matches the path.
345 4. this does lstat(2) and finds index does not match the
346 path.
347 5. registering the new version to index sets "assume
348 unchanged" bit.
349 6. and it is assumed unchanged.
350 7. even after you edit it.
351 8. you can tell about the change after the fact.
352 9. now it checks with lstat(2) and finds it has been changed.
353
355 Skip-worktree bit can be defined in one (long) sentence: Tell git to
356 avoid writing the file to the working directory when reasonably
357 possible, and treat the file as unchanged when it is not present in the
358 working directory.
359
360 Note that not all git commands will pay attention to this bit, and some
361 only partially support it.
362
363 The update-index flags and the read-tree capabilities relating to the
364 skip-worktree bit predated the introduction of the git-sparse-
365 checkout(1) command, which provides a much easier way to configure and
366 handle the skip-worktree bits. If you want to reduce your working tree
367 to only deal with a subset of the files in the repository, we strongly
368 encourage the use of git-sparse-checkout(1) in preference to the
369 low-level update-index and read-tree primitives.
370
371 The primary purpose of the skip-worktree bit is to enable sparse
372 checkouts, i.e. to have working directories with only a subset of paths
373 present. When the skip-worktree bit is set, Git commands (such as
374 switch, pull, merge) will avoid writing these files. However, these
375 commands will sometimes write these files anyway in important cases
376 such as conflicts during a merge or rebase. Git commands will also
377 avoid treating the lack of such files as an intentional deletion; for
378 example git add -u will not not stage a deletion for these files and
379 git commit -a will not make a commit deleting them either.
380
381 Although this bit looks similar to assume-unchanged bit, its goal is
382 different. The assume-unchanged bit is for leaving the file in the
383 working tree but having Git omit checking it for changes and presuming
384 that the file has not been changed (though if it can determine without
385 stat’ing the file that it has changed, it is free to record the
386 changes). skip-worktree tells Git to ignore the absence of the file,
387 avoid updating it when possible with commands that normally update much
388 of the working directory (e.g. checkout, switch, pull, etc.), and not
389 have its absence be recorded in commits. Note that in sparse checkouts
390 (setup by git sparse-checkout or by configuring core.sparseCheckout to
391 true), if a file is marked as skip-worktree in the index but is found
392 in the working tree, Git will clear the skip-worktree bit for that
393 file.
394
396 This mode is designed for repositories with very large indexes, and
397 aims at reducing the time it takes to repeatedly write these indexes.
398
399 In this mode, the index is split into two files, $GIT_DIR/index and
400 $GIT_DIR/sharedindex.<SHA-1>. Changes are accumulated in
401 $GIT_DIR/index, the split index, while the shared index file contains
402 all index entries and stays unchanged.
403
404 All changes in the split index are pushed back to the shared index file
405 when the number of entries in the split index reaches a level specified
406 by the splitIndex.maxPercentChange config variable (see git-config(1)).
407
408 Each time a new shared index file is created, the old shared index
409 files are deleted if their modification time is older than what is
410 specified by the splitIndex.sharedIndexExpire config variable (see git-
411 config(1)).
412
413 To avoid deleting a shared index file that is still used, its
414 modification time is updated to the current time every time a new split
415 index based on the shared index file is either created or read from.
416
418 This cache is meant to speed up commands that involve determining
419 untracked files such as git status.
420
421 This feature works by recording the mtime of the working tree
422 directories and then omitting reading directories and stat calls
423 against files in those directories whose mtime hasn’t changed. For this
424 to work the underlying operating system and file system must change the
425 st_mtime field of directories if files in the directory are added,
426 modified or deleted.
427
428 You can test whether the filesystem supports that with the
429 --test-untracked-cache option. The --untracked-cache option used to
430 implicitly perform that test in older versions of Git, but that’s no
431 longer the case.
432
433 If you want to enable (or disable) this feature, it is easier to use
434 the core.untrackedCache configuration variable (see git-config(1)) than
435 using the --untracked-cache option to git update-index in each
436 repository, especially if you want to do so across all repositories you
437 use, because you can set the configuration variable to true (or false)
438 in your $HOME/.gitconfig just once and have it affect all repositories
439 you touch.
440
441 When the core.untrackedCache configuration variable is changed, the
442 untracked cache is added to or removed from the index the next time a
443 command reads the index; while when --[no-|force-]untracked-cache are
444 used, the untracked cache is immediately added to or removed from the
445 index.
446
447 Before 2.17, the untracked cache had a bug where replacing a directory
448 with a symlink to another directory could cause it to incorrectly show
449 files tracked by git as untracked. See the "status: add a failing test
450 showing a core.untrackedCache bug" commit to git.git. A workaround for
451 that is (and this might work for other undiscovered bugs in the
452 future):
453
454 $ git -c core.untrackedCache=false status
455
456 This bug has also been shown to affect non-symlink cases of replacing a
457 directory with a file when it comes to the internal structures of the
458 untracked cache, but no case has been reported where this resulted in
459 wrong "git status" output.
460
461 There are also cases where existing indexes written by git versions
462 before 2.17 will reference directories that don’t exist anymore,
463 potentially causing many "could not open directory" warnings to be
464 printed on "git status". These are new warnings for existing issues
465 that were previously silently discarded.
466
467 As with the bug described above the solution is to one-off do a "git
468 status" run with core.untrackedCache=false to flush out the leftover
469 bad data.
470
472 This feature is intended to speed up git operations for repos that have
473 large working directories.
474
475 It enables git to work together with a file system monitor (see git-
476 fsmonitor--daemon(1) and the "fsmonitor-watchman" section of
477 githooks(5)) that can inform it as to what files have been modified.
478 This enables git to avoid having to lstat() every file to find modified
479 files.
480
481 When used in conjunction with the untracked cache, it can further
482 improve performance by avoiding the cost of scanning the entire working
483 directory looking for new files.
484
485 If you want to enable (or disable) this feature, it is easier to use
486 the core.fsmonitor configuration variable (see git-config(1)) than
487 using the --fsmonitor option to git update-index in each repository,
488 especially if you want to do so across all repositories you use,
489 because you can set the configuration variable in your $HOME/.gitconfig
490 just once and have it affect all repositories you touch.
491
492 When the core.fsmonitor configuration variable is changed, the file
493 system monitor is added to or removed from the index the next time a
494 command reads the index. When --[no-]fsmonitor are used, the file
495 system monitor is immediately added to or removed from the index.
496
498 The command honors core.filemode configuration variable. If your
499 repository is on a filesystem whose executable bits are unreliable,
500 this should be set to false (see git-config(1)). This causes the
501 command to ignore differences in file modes recorded in the index and
502 the file mode on the filesystem if they differ only on executable bit.
503 On such an unfortunate filesystem, you may need to use git update-index
504 --chmod=.
505
506 Quite similarly, if core.symlinks configuration variable is set to
507 false (see git-config(1)), symbolic links are checked out as plain
508 files, and this command does not modify a recorded file mode from
509 symbolic link to regular file.
510
511 The command looks at core.ignorestat configuration variable. See Using
512 "assume unchanged" bit section above.
513
514 The command also looks at core.trustctime configuration variable. It
515 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 git-config(1)).
518
519 The untracked cache extension can be enabled by the core.untrackedCache
520 configuration variable (see git-config(1)).
521
523 Users often try to use the assume-unchanged and skip-worktree bits to
524 tell Git to ignore changes to files that are tracked. This does not
525 work as expected, since Git may still check working tree files against
526 the index when performing certain operations. In general, Git does not
527 provide a way to ignore changes to tracked files, so alternate
528 solutions are recommended.
529
530 For example, if the file you want to change is some sort of config
531 file, the repository can include a sample config file that can then be
532 copied into the ignored name and modified. The repository can even
533 include a script to treat the sample file as a template, modifying and
534 copying it automatically.
535
537 git-config(1), git-add(1), git-ls-files(1)
538
540 Part of the git(1) suite
541
542
543
544Git 2.36.1 2022-05-05 GIT-UPDATE-INDEX(1)