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 files.
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 a 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 names 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 names 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 of 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 a list of paths from the command line, read a
143 list of paths from the standard input. Paths are separated by LF
144 (i.e. one path per line) by default.
145
146 --verbose
147 Report what is being added and removed from the 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
152 2 or 3, depending on whether extra features are used, such as git
153 add -N. With --verbose, also report the version the index file uses
154 before and after this command.
155
156 Version 4 performs a simple pathname compression that reduces index
157 size by 30%-50% on large repositories, which results in faster load
158 time. Git supports it since version 1.8.0, released in October
159 2012, and support for it was added to libgit2 in 2016 and to JGit
160 in 2020. Older versions of this manual page called it "relatively
161 young", but it should be considered mature technology these days.
162
163 --show-index-version
164 Report the index format version used by the on-disk index file. See
165 --index-version above.
166
167 -z
168 Only meaningful with --stdin or --index-info; paths are separated
169 with NUL character instead of LF.
170
171 --split-index, --no-split-index
172 Enable or disable split index mode. If split-index mode is already
173 enabled and --split-index is given again, all changes in
174 $GIT_DIR/index are pushed back to the shared index file.
175
176 These options take effect whatever the value of the core.splitIndex
177 configuration variable (see git-config(1)). But a warning is
178 emitted when the change goes against the configured value, as the
179 configured value will take effect next time the index is read and
180 this will remove the intended effect of the option.
181
182 --untracked-cache, --no-untracked-cache
183 Enable or disable untracked cache feature. Please use
184 --test-untracked-cache before enabling it.
185
186 These options take effect whatever the value of the
187 core.untrackedCache configuration variable (see git-config(1)). But
188 a warning is emitted when the change goes against the configured
189 value, as the configured value will take effect next time the index
190 is read and this will remove the intended effect of the option.
191
192 --test-untracked-cache
193 Only perform tests on the working directory to make sure untracked
194 cache can be used. You have to manually enable untracked cache
195 using --untracked-cache or --force-untracked-cache or the
196 core.untrackedCache configuration variable afterwards if you really
197 want to use it. If a test fails the exit code is 1 and a message
198 explains what is not working as needed, otherwise the exit code is
199 0 and OK is printed.
200
201 --force-untracked-cache
202 Same as --untracked-cache. Provided for backwards compatibility
203 with older versions of Git where --untracked-cache used to imply
204 --test-untracked-cache but this option would enable the extension
205 unconditionally.
206
207 --fsmonitor, --no-fsmonitor
208 Enable or disable files system monitor feature. These options take
209 effect whatever the value of the core.fsmonitor configuration
210 variable (see git-config(1)). But a warning is emitted when the
211 change goes against the configured value, as the configured value
212 will take effect next time the index is read and this will remove
213 the intended effect of the option.
214
215 --
216 Do not interpret any more arguments as options.
217
218 <file>
219 Files to act on. Note that files beginning with . are discarded.
220 This includes ./file and dir/./file. If you don’t want this, then
221 use cleaner names. The same applies to directories ending / and
222 paths with //
223
225 --refresh does not calculate a new sha1 file or bring the index up to
226 date for mode/content changes. But what it does do is to "re-match" the
227 stat information of a file with the index, so that you can refresh the
228 index for a file that hasn’t been changed but where the stat entry is
229 out of date.
230
231 For example, you’d want to do this after doing a git read-tree, to link
232 up the stat index details with the proper files.
233
235 --cacheinfo is used to register a file that is not in the current
236 working directory. This is useful for minimum-checkout merging.
237
238 To pretend you have a file at path with mode and sha1, say:
239
240 $ git update-index --add --cacheinfo <mode>,<sha1>,<path>
241
242 --info-only is used to register files without placing them in the
243 object database. This is useful for status-only repositories.
244
245 Both --cacheinfo and --info-only behave similarly: the index is updated
246 but the object database isn’t. --cacheinfo is useful when the object is
247 in the database but the file isn’t available locally. --info-only is
248 useful when the file is available, but you do not wish to update the
249 object database.
250
252 --index-info is a more powerful mechanism that lets you feed multiple
253 entry definitions from the standard input, and designed specifically
254 for scripts. It can take inputs of three formats:
255
256 1. mode SP type SP sha1 TAB path
257
258 This format is to stuff git ls-tree output into the index.
259
260 2. mode SP sha1 SP stage TAB path
261
262 This format is to put higher order stages into the index file and
263 matches git ls-files --stage output.
264
265 3. mode SP sha1 TAB path
266
267 This format is no longer produced by any Git command, but is and
268 will continue to be supported by update-index --index-info.
269
270 To place a higher stage entry to the index, the path should first be
271 removed by feeding a mode=0 entry for the path, and then feeding
272 necessary input lines in the third format.
273
274 For example, starting with this index:
275
276 $ git ls-files -s
277 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 0 frotz
278
279 you can feed the following input to --index-info:
280
281 $ git update-index --index-info
282 0 0000000000000000000000000000000000000000 frotz
283 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz
284 100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz
285
286 The first line of the input feeds 0 as the mode to remove the path; the
287 SHA-1 does not matter as long as it is well formatted. Then the second
288 and third line feeds stage 1 and stage 2 entries for that path. After
289 the above, we would end up with this:
290
291 $ git ls-files -s
292 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz
293 100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz
294
296 Many operations in Git depend on your filesystem to have an efficient
297 lstat(2) implementation, so that st_mtime information for working tree
298 files can be cheaply checked to see if the file contents have changed
299 from the version recorded in the index file. Unfortunately, some
300 filesystems have inefficient lstat(2). If your filesystem is one of
301 them, you can set "assume unchanged" bit to paths you have not changed
302 to cause Git not to do this check. Note that setting this bit on a path
303 does not mean Git will check the contents of the file to see if it has
304 changed — it makes Git to omit any checking and assume it has not
305 changed. When you make changes to working tree files, you have to
306 explicitly tell Git about it by dropping "assume unchanged" bit, either
307 before or after you modify them.
308
309 In order to set "assume unchanged" bit, use --assume-unchanged option.
310 To unset, use --no-assume-unchanged. To see which files have the
311 "assume unchanged" bit set, use git ls-files -v (see git-ls-files(1)).
312
313 The command looks at core.ignorestat configuration variable. When this
314 is true, paths updated with git update-index paths... and paths updated
315 with other Git commands that update both index and working tree (e.g.
316 git apply --index, git checkout-index -u, and git read-tree -u) are
317 automatically marked as "assume unchanged". Note that "assume
318 unchanged" bit is not set if git update-index --refresh finds the
319 working tree file matches the index (use git update-index
320 --really-refresh if you want to mark them as "assume unchanged").
321
322 Sometimes users confuse the assume-unchanged bit with the skip-worktree
323 bit. See the final paragraph in the "Skip-worktree bit" section below
324 for an explanation of the differences.
325
327 To update and refresh only the files already checked out:
328
329 $ git checkout-index -n -f -a && git update-index --ignore-missing --refresh
330
331 On an inefficient filesystem with core.ignorestat set
332
333 $ git update-index --really-refresh [1m(1)
334 $ git update-index --no-assume-unchanged foo.c [1m(2)
335 $ git diff --name-only [1m(3)
336 $ edit foo.c
337 $ git diff --name-only [1m(4)
338 M foo.c
339 $ git update-index foo.c [1m(5)
340 $ git diff --name-only [1m(6)
341 $ edit foo.c
342 $ git diff --name-only [1m(7)
343 $ git update-index --no-assume-unchanged foo.c [1m(8)
344 $ git diff --name-only [1m(9)
345 M foo.c
346
347 1. forces lstat(2) to set "assume unchanged" bits for paths
348 that match index.
349 2. mark the path to be edited.
350 3. this does lstat(2) and finds index matches the path.
351 4. this does lstat(2) and finds index does not match the
352 path.
353 5. registering the new version to index sets "assume
354 unchanged" bit.
355 6. and it is assumed unchanged.
356 7. even after you edit it.
357 8. you can tell about the change after the fact.
358 9. now it checks with lstat(2) and finds it has been changed.
359
361 Skip-worktree bit can be defined in one (long) sentence: Tell git to
362 avoid writing the file to the working directory when reasonably
363 possible, and treat the file as unchanged when it is not present in the
364 working directory.
365
366 Note that not all git commands will pay attention to this bit, and some
367 only partially support it.
368
369 The update-index flags and the read-tree capabilities relating to the
370 skip-worktree bit predated the introduction of the git-sparse-
371 checkout(1) command, which provides a much easier way to configure and
372 handle the skip-worktree bits. If you want to reduce your working tree
373 to only deal with a subset of the files in the repository, we strongly
374 encourage the use of git-sparse-checkout(1) in preference to the
375 low-level update-index and read-tree primitives.
376
377 The primary purpose of the skip-worktree bit is to enable sparse
378 checkouts, i.e. to have working directories with only a subset of paths
379 present. When the skip-worktree bit is set, Git commands (such as
380 switch, pull, merge) will avoid writing these files. However, these
381 commands will sometimes write these files anyway in important cases
382 such as conflicts during a merge or rebase. Git commands will also
383 avoid treating the lack of such files as an intentional deletion; for
384 example git add -u will not stage a deletion for these files and git
385 commit -a will not make a commit deleting them either.
386
387 Although this bit looks similar to assume-unchanged bit, its goal is
388 different. The assume-unchanged bit is for leaving the file in the
389 working tree but having Git omit checking it for changes and presuming
390 that the file has not been changed (though if it can determine without
391 stat’ing the file that it has changed, it is free to record the
392 changes). skip-worktree tells Git to ignore the absence of the file,
393 avoid updating it when possible with commands that normally update much
394 of the working directory (e.g. checkout, switch, pull, etc.), and not
395 have its absence be recorded in commits. Note that in sparse checkouts
396 (setup by git sparse-checkout or by configuring core.sparseCheckout to
397 true), if a file is marked as skip-worktree in the index but is found
398 in the working tree, Git will clear the skip-worktree bit for that
399 file.
400
402 This mode is designed for repositories with very large indexes, and
403 aims at reducing the time it takes to repeatedly write these indexes.
404
405 In this mode, the index is split into two files, $GIT_DIR/index and
406 $GIT_DIR/sharedindex.<SHA-1>. Changes are accumulated in
407 $GIT_DIR/index, the split index, while the shared index file contains
408 all index entries and stays unchanged.
409
410 All changes in the split index are pushed back to the shared index file
411 when the number of entries in the split index reaches a level specified
412 by the splitIndex.maxPercentChange config variable (see git-config(1)).
413
414 Each time a new shared index file is created, the old shared index
415 files are deleted if their modification time is older than what is
416 specified by the splitIndex.sharedIndexExpire config variable (see git-
417 config(1)).
418
419 To avoid deleting a shared index file that is still used, its
420 modification time is updated to the current time every time a new split
421 index based on the shared index file is either created or read from.
422
424 This cache is meant to speed up commands that involve determining
425 untracked files such as git status.
426
427 This feature works by recording the mtime of the working tree
428 directories and then omitting reading directories and stat calls
429 against files in those directories whose mtime hasn’t changed. For this
430 to work the underlying operating system and file system must change the
431 st_mtime field of directories if files in the directory are added,
432 modified or deleted.
433
434 You can test whether the filesystem supports that with the
435 --test-untracked-cache option. The --untracked-cache option used to
436 implicitly perform that test in older versions of Git, but that’s no
437 longer the case.
438
439 If you want to enable (or disable) this feature, it is easier to use
440 the core.untrackedCache configuration variable (see git-config(1)) than
441 using the --untracked-cache option to git update-index in each
442 repository, especially if you want to do so across all repositories you
443 use, because you can set the configuration variable to true (or false)
444 in your $HOME/.gitconfig just once and have it affect all repositories
445 you touch.
446
447 When the core.untrackedCache configuration variable is changed, the
448 untracked cache is added to or removed from the index the next time a
449 command reads the index; while when --[no-|force-]untracked-cache are
450 used, the untracked cache is immediately added to or removed from the
451 index.
452
453 Before 2.17, the untracked cache had a bug where replacing a directory
454 with a symlink to another directory could cause it to incorrectly show
455 files tracked by git as untracked. See the "status: add a failing test
456 showing a core.untrackedCache bug" commit to git.git. A workaround for
457 that is (and this might work for other undiscovered bugs in the
458 future):
459
460 $ git -c core.untrackedCache=false status
461
462 This bug has also been shown to affect non-symlink cases of replacing a
463 directory with a file when it comes to the internal structures of the
464 untracked cache, but no case has been reported where this resulted in
465 wrong "git status" output.
466
467 There are also cases where existing indexes written by git versions
468 before 2.17 will reference directories that don’t exist anymore,
469 potentially causing many "could not open directory" warnings to be
470 printed on "git status". These are new warnings for existing issues
471 that were previously silently discarded.
472
473 As with the bug described above the solution is to one-off do a "git
474 status" run with core.untrackedCache=false to flush out the leftover
475 bad data.
476
478 This feature is intended to speed up git operations for repos that have
479 large working directories.
480
481 It enables git to work together with a file system monitor (see git-
482 fsmonitor--daemon(1) and the "fsmonitor-watchman" section of
483 githooks(5)) that can inform it as to what files have been modified.
484 This enables git to avoid having to lstat() every file to find modified
485 files.
486
487 When used in conjunction with the untracked cache, it can further
488 improve performance by avoiding the cost of scanning the entire working
489 directory looking for new files.
490
491 If you want to enable (or disable) this feature, it is easier to use
492 the core.fsmonitor configuration variable (see git-config(1)) than
493 using the --fsmonitor option to git update-index in each repository,
494 especially if you want to do so across all repositories you use,
495 because you can set the configuration variable in your $HOME/.gitconfig
496 just once and have it affect all repositories you touch.
497
498 When the core.fsmonitor configuration variable is changed, the file
499 system monitor is added to or removed from the index the next time a
500 command reads the index. When --[no-]fsmonitor are used, the file
501 system monitor is immediately added to or removed from the index.
502
504 The command honors core.filemode configuration variable. If your
505 repository is on a filesystem whose executable bits are unreliable,
506 this should be set to false (see git-config(1)). This causes the
507 command to ignore differences in file modes recorded in the index and
508 the file mode on the filesystem if they differ only on executable bit.
509 On such an unfortunate filesystem, you may need to use git update-index
510 --chmod=.
511
512 Quite similarly, if core.symlinks configuration variable is set to
513 false (see git-config(1)), symbolic links are checked out as plain
514 files, and this command does not modify a recorded file mode from
515 symbolic link to regular file.
516
517 The command looks at core.ignorestat configuration variable. See Using
518 "assume unchanged" bit section above.
519
520 The command also looks at core.trustctime configuration variable. It
521 can be useful when the inode change time is regularly modified by
522 something outside Git (file system crawlers and backup systems use
523 ctime for marking files processed) (see git-config(1)).
524
525 The untracked cache extension can be enabled by the core.untrackedCache
526 configuration variable (see git-config(1)).
527
529 Users often try to use the assume-unchanged and skip-worktree bits to
530 tell Git to ignore changes to files that are tracked. This does not
531 work as expected, since Git may still check working tree files against
532 the index when performing certain operations. In general, Git does not
533 provide a way to ignore changes to tracked files, so alternate
534 solutions are recommended.
535
536 For example, if the file you want to change is some sort of config
537 file, the repository can include a sample config file that can then be
538 copied into the ignored name and modified. The repository can even
539 include a script to treat the sample file as a template, modifying and
540 copying it automatically.
541
543 git-config(1), git-add(1), git-ls-files(1)
544
546 Part of the git(1) suite
547
548
549
550Git 2.43.0 11/20/2023 GIT-UPDATE-INDEX(1)