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
317 To update and refresh only the files already checked out:
318
319 $ git checkout-index -n -f -a && git update-index --ignore-missing --refresh
320
321 On an inefficient filesystem with core.ignorestat set
322
323 $ git update-index --really-refresh [1m(1)
324 $ git update-index --no-assume-unchanged foo.c [1m(2)
325 $ git diff --name-only [1m(3)
326 $ edit foo.c
327 $ git diff --name-only [1m(4)
328 M foo.c
329 $ git update-index foo.c [1m(5)
330 $ git diff --name-only [1m(6)
331 $ edit foo.c
332 $ git diff --name-only [1m(7)
333 $ git update-index --no-assume-unchanged foo.c [1m(8)
334 $ git diff --name-only [1m(9)
335 M foo.c
336
337 1. forces lstat(2) to set "assume unchanged" bits for paths
338 that match index.
339 2. mark the path to be edited.
340 3. this does lstat(2) and finds index matches the path.
341 4. this does lstat(2) and finds index does not match the
342 path.
343 5. registering the new version to index sets "assume
344 unchanged" bit.
345 6. and it is assumed unchanged.
346 7. even after you edit it.
347 8. you can tell about the change after the fact.
348 9. now it checks with lstat(2) and finds it has been changed.
349
351 Skip-worktree bit can be defined in one (long) sentence: When reading
352 an entry, if it is marked as skip-worktree, then Git pretends its
353 working directory version is up to date and read the index version
354 instead.
355
356 To elaborate, "reading" means checking for file existence, reading file
357 attributes or file content. The working directory version may be
358 present or absent. If present, its content may match against the index
359 version or not. Writing is not affected by this bit, content safety is
360 still first priority. Note that Git can update working directory file,
361 that is marked skip-worktree, if it is safe to do so (i.e. working
362 directory version matches index version)
363
364 Although this bit looks similar to assume-unchanged bit, its goal is
365 different from assume-unchanged bit’s. Skip-worktree also takes
366 precedence over assume-unchanged bit when both are set.
367
369 This mode is designed for repositories with very large indexes, and
370 aims at reducing the time it takes to repeatedly write these indexes.
371
372 In this mode, the index is split into two files, $GIT_DIR/index and
373 $GIT_DIR/sharedindex.<SHA-1>. Changes are accumulated in
374 $GIT_DIR/index, the split index, while the shared index file contains
375 all index entries and stays unchanged.
376
377 All changes in the split index are pushed back to the shared index file
378 when the number of entries in the split index reaches a level specified
379 by the splitIndex.maxPercentChange config variable (see git-config(1)).
380
381 Each time a new shared index file is created, the old shared index
382 files are deleted if their modification time is older than what is
383 specified by the splitIndex.sharedIndexExpire config variable (see git-
384 config(1)).
385
386 To avoid deleting a shared index file that is still used, its
387 modification time is updated to the current time every time a new split
388 index based on the shared index file is either created or read from.
389
391 This cache is meant to speed up commands that involve determining
392 untracked files such as git status.
393
394 This feature works by recording the mtime of the working tree
395 directories and then omitting reading directories and stat calls
396 against files in those directories whose mtime hasn’t changed. For this
397 to work the underlying operating system and file system must change the
398 st_mtime field of directories if files in the directory are added,
399 modified or deleted.
400
401 You can test whether the filesystem supports that with the
402 --test-untracked-cache option. The --untracked-cache option used to
403 implicitly perform that test in older versions of Git, but that’s no
404 longer the case.
405
406 If you want to enable (or disable) this feature, it is easier to use
407 the core.untrackedCache configuration variable (see git-config(1)) than
408 using the --untracked-cache option to git update-index in each
409 repository, especially if you want to do so across all repositories you
410 use, because you can set the configuration variable to true (or false)
411 in your $HOME/.gitconfig just once and have it affect all repositories
412 you touch.
413
414 When the core.untrackedCache configuration variable is changed, the
415 untracked cache is added to or removed from the index the next time a
416 command reads the index; while when --[no-|force-]untracked-cache are
417 used, the untracked cache is immediately added to or removed from the
418 index.
419
420 Before 2.17, the untracked cache had a bug where replacing a directory
421 with a symlink to another directory could cause it to incorrectly show
422 files tracked by git as untracked. See the "status: add a failing test
423 showing a core.untrackedCache bug" commit to git.git. A workaround for
424 that is (and this might work for other undiscovered bugs in the
425 future):
426
427 $ git -c core.untrackedCache=false status
428
429 This bug has also been shown to affect non-symlink cases of replacing a
430 directory with a file when it comes to the internal structures of the
431 untracked cache, but no case has been reported where this resulted in
432 wrong "git status" output.
433
434 There are also cases where existing indexes written by git versions
435 before 2.17 will reference directories that don’t exist anymore,
436 potentially causing many "could not open directory" warnings to be
437 printed on "git status". These are new warnings for existing issues
438 that were previously silently discarded.
439
440 As with the bug described above the solution is to one-off do a "git
441 status" run with core.untrackedCache=false to flush out the leftover
442 bad data.
443
445 This feature is intended to speed up git operations for repos that have
446 large working directories.
447
448 It enables git to work together with a file system monitor (see the
449 "fsmonitor-watchman" section of githooks(5)) that can inform it as to
450 what files have been modified. This enables git to avoid having to
451 lstat() every file to find modified files.
452
453 When used in conjunction with the untracked cache, it can further
454 improve performance by avoiding the cost of scanning the entire working
455 directory looking for new files.
456
457 If you want to enable (or disable) this feature, it is easier to use
458 the core.fsmonitor configuration variable (see git-config(1)) than
459 using the --fsmonitor option to git update-index in each repository,
460 especially if you want to do so across all repositories you use,
461 because you can set the configuration variable in your $HOME/.gitconfig
462 just once and have it affect all repositories you touch.
463
464 When the core.fsmonitor configuration variable is changed, the file
465 system monitor is added to or removed from the index the next time a
466 command reads the index. When --[no-]fsmonitor are used, the file
467 system monitor is immediately added to or removed from the index.
468
470 The command honors core.filemode configuration variable. If your
471 repository is on a filesystem whose executable bits are unreliable,
472 this should be set to false (see git-config(1)). This causes the
473 command to ignore differences in file modes recorded in the index and
474 the file mode on the filesystem if they differ only on executable bit.
475 On such an unfortunate filesystem, you may need to use git update-index
476 --chmod=.
477
478 Quite similarly, if core.symlinks configuration variable is set to
479 false (see git-config(1)), symbolic links are checked out as plain
480 files, and this command does not modify a recorded file mode from
481 symbolic link to regular file.
482
483 The command looks at core.ignorestat configuration variable. See Using
484 "assume unchanged" bit section above.
485
486 The command also looks at core.trustctime configuration variable. It
487 can be useful when the inode change time is regularly modified by
488 something outside Git (file system crawlers and backup systems use
489 ctime for marking files processed) (see git-config(1)).
490
491 The untracked cache extension can be enabled by the core.untrackedCache
492 configuration variable (see git-config(1)).
493
495 Users often try to use the assume-unchanged and skip-worktree bits to
496 tell Git to ignore changes to files that are tracked. This does not
497 work as expected, since Git may still check working tree files against
498 the index when performing certain operations. In general, Git does not
499 provide a way to ignore changes to tracked files, so alternate
500 solutions are recommended.
501
502 For example, if the file you want to change is some sort of config
503 file, the repository can include a sample config file that can then be
504 copied into the ignored name and modified. The repository can even
505 include a script to treat the sample file as a template, modifying and
506 copying it automatically.
507
509 git-config(1), git-add(1), git-ls-files(1)
510
512 Part of the git(1) suite
513
514
515
516Git 2.31.1 2021-03-26 GIT-UPDATE-INDEX(1)