1GIT-UPDATE-INDEX(1)               Git Manual               GIT-UPDATE-INDEX(1)
2
3
4

NAME

6       git-update-index - Register file contents in the working tree to the
7       index
8

SYNOPSIS

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-]fsmonitor-valid]
18                    [--ignore-submodules]
19                    [--[no-]split-index]
20                    [--[no-|test-|force-]untracked-cache]
21                    [--[no-]fsmonitor]
22                    [--really-refresh] [--unresolve] [--again | -g]
23                    [--info-only] [--index-info]
24                    [-z] [--stdin] [--index-version <n>]
25                    [--verbose]
26                    [--] [<file>...]
27
28

DESCRIPTION

30       Modifies the index or directory cache. Each file mentioned is updated
31       into the index and 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

OPTIONS

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-]fsmonitor-valid
108           When one of these flags is specified, the object name recorded for
109           the paths are not updated. Instead, these options set and unset the
110           "fsmonitor valid" bit for the paths. See section "File System
111           Monitor" below for more information.
112
113       -g, --again
114           Runs git update-index itself on the paths whose index entries are
115           different from those from the HEAD commit.
116
117       --unresolve
118           Restores the unmerged or needs updating state of a file during a
119           merge if it was cleared by accident.
120
121       --info-only
122           Do not create objects in the object database for all <file>
123           arguments that follow this flag; just insert their object IDs into
124           the index.
125
126       --force-remove
127           Remove the file from the index even when the working directory
128           still has such a file. (Implies --remove.)
129
130       --replace
131           By default, when a file path exists in the index, git update-index
132           refuses an attempt to add path/file. Similarly if a file path/file
133           exists, a file path cannot be added. With --replace flag, existing
134           entries that conflict with the entry being added are automatically
135           removed with warning messages.
136
137       --stdin
138           Instead of taking list of paths from the command line, read list of
139           paths from the standard input. Paths are separated by LF (i.e. one
140           path per line) by default.
141
142       --verbose
143           Report what is being added and removed from index.
144
145       --index-version <n>
146           Write the resulting index out in the named on-disk format version.
147           Supported versions are 2, 3 and 4. The current default version is 2
148           or 3, depending on whether extra features are used, such as git add
149           -N.
150
151           Version 4 performs a simple pathname compression that reduces index
152           size by 30%-50% on large repositories, which results in faster load
153           time. Version 4 is relatively young (first released in 1.8.0 in
154           October 2012). Other Git implementations such as JGit and libgit2
155           may not support it yet.
156
157       -z
158           Only meaningful with --stdin or --index-info; paths are separated
159           with NUL character instead of LF.
160
161       --split-index, --no-split-index
162           Enable or disable split index mode. If split-index mode is already
163           enabled and --split-index is given again, all changes in
164           $GIT_DIR/index are pushed back to the shared index file.
165
166           These options take effect whatever the value of the core.splitIndex
167           configuration variable (see git-config(1)). But a warning is
168           emitted when the change goes against the configured value, as the
169           configured value will take effect next time the index is read and
170           this will remove the intended effect of the option.
171
172       --untracked-cache, --no-untracked-cache
173           Enable or disable untracked cache feature. Please use
174           --test-untracked-cache before enabling it.
175
176           These options take effect whatever the value of the
177           core.untrackedCache configuration variable (see git-config(1)). But
178           a warning is emitted when the change goes against the configured
179           value, as the configured value will take effect next time the index
180           is read and this will remove the intended effect of the option.
181
182       --test-untracked-cache
183           Only perform tests on the working directory to make sure untracked
184           cache can be used. You have to manually enable untracked cache
185           using --untracked-cache or --force-untracked-cache or the
186           core.untrackedCache configuration variable afterwards if you really
187           want to use it. If a test fails the exit code is 1 and a message
188           explains what is not working as needed, otherwise the exit code is
189           0 and OK is printed.
190
191       --force-untracked-cache
192           Same as --untracked-cache. Provided for backwards compatibility
193           with older versions of Git where --untracked-cache used to imply
194           --test-untracked-cache but this option would enable the extension
195           unconditionally.
196
197       --fsmonitor, --no-fsmonitor
198           Enable or disable files system monitor feature. These options take
199           effect whatever the value of the core.fsmonitor configuration
200           variable (see git-config(1)). But a warning is emitted when the
201           change goes against the configured value, as the configured value
202           will take effect next time the index is read and this will remove
203           the intended effect of the option.
204
205       --
206           Do not interpret any more arguments as options.
207
208       <file>
209           Files to act on. Note that files beginning with .  are discarded.
210           This includes ./file and dir/./file. If you don’t want this, then
211           use cleaner names. The same applies to directories ending / and
212           paths with //
213

USING --REFRESH

215       --refresh does not calculate a new sha1 file or bring the index up to
216       date for mode/content changes. But what it does do is to "re-match" the
217       stat information of a file with the index, so that you can refresh the
218       index for a file that hasn’t been changed but where the stat entry is
219       out of date.
220
221       For example, you’d want to do this after doing a git read-tree, to link
222       up the stat index details with the proper files.
223

USING --CACHEINFO OR --INFO-ONLY

225       --cacheinfo is used to register a file that is not in the current
226       working directory. This is useful for minimum-checkout merging.
227
228       To pretend you have a file at path with mode and sha1, say:
229
230           $ git update-index --add --cacheinfo <mode>,<sha1>,<path>
231
232
233       --info-only is used to register files without placing them in the
234       object database. This is useful for status-only repositories.
235
236       Both --cacheinfo and --info-only behave similarly: the index is updated
237       but the object database isn’t. --cacheinfo is useful when the object is
238       in the database but the file isn’t available locally. --info-only is
239       useful when the file is available, but you do not wish to update the
240       object database.
241

USING --INDEX-INFO

243       --index-info is a more powerful mechanism that lets you feed multiple
244       entry definitions from the standard input, and designed specifically
245       for scripts. It can take inputs of three formats:
246
247        1. mode SP type SP sha1 TAB path
248
249           This format is to stuff git ls-tree output into the index.
250
251        2. mode SP sha1 SP stage TAB path
252
253           This format is to put higher order stages into the index file and
254           matches git ls-files --stage output.
255
256        3. mode SP sha1 TAB path
257
258           This format is no longer produced by any Git command, but is and
259           will continue to be supported by update-index --index-info.
260
261       To place a higher stage entry to the index, the path should first be
262       removed by feeding a mode=0 entry for the path, and then feeding
263       necessary input lines in the third format.
264
265       For example, starting with this index:
266
267           $ git ls-files -s
268           100644 8a1218a1024a212bb3db30becd860315f9f3ac52 0       frotz
269
270
271       you can feed the following input to --index-info:
272
273           $ git update-index --index-info
274           0 0000000000000000000000000000000000000000      frotz
275           100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1       frotz
276           100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2       frotz
277
278
279       The first line of the input feeds 0 as the mode to remove the path; the
280       SHA-1 does not matter as long as it is well formatted. Then the second
281       and third line feeds stage 1 and stage 2 entries for that path. After
282       the above, we would end up with this:
283
284           $ git ls-files -s
285           100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1       frotz
286           100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2       frotz
287
288

USING “ASSUME UNCHANGED” BIT

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

EXAMPLES

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
322
323       On an inefficient filesystem with core.ignorestat set
324
325               $ git update-index --really-refresh              (1)
326               $ git update-index --no-assume-unchanged foo.c   (2)
327               $ git diff --name-only                           (3)
328               $ edit foo.c
329               $ git diff --name-only                           (4)
330               M foo.c
331               $ git update-index foo.c                         (5)
332               $ git diff --name-only                           (6)
333               $ edit foo.c
334               $ git diff --name-only                           (7)
335               $ git update-index --no-assume-unchanged foo.c   (8)
336               $ git diff --name-only                           (9)
337               M foo.c
338
339           1. forces lstat(2) to set "assume unchanged" bits for paths that
340           match index.
341           2. mark the path to be edited.
342           3. this does lstat(2) and finds index matches the path.
343           4. this does lstat(2) and finds index does not match the path.
344           5. registering the new version to index sets "assume unchanged"
345           bit.
346           6. and it is assumed unchanged.
347           7. even after you edit it.
348           8. you can tell about the change after the fact.
349           9. now it checks with lstat(2) and finds it has been changed.
350

SKIP-WORKTREE BIT

352       Skip-worktree bit can be defined in one (long) sentence: When reading
353       an entry, if it is marked as skip-worktree, then Git pretends its
354       working directory version is up to date and read the index version
355       instead.
356
357       To elaborate, "reading" means checking for file existence, reading file
358       attributes or file content. The working directory version may be
359       present or absent. If present, its content may match against the index
360       version or not. Writing is not affected by this bit, content safety is
361       still first priority. Note that Git can update working directory file,
362       that is marked skip-worktree, if it is safe to do so (i.e. working
363       directory version matches index version)
364
365       Although this bit looks similar to assume-unchanged bit, its goal is
366       different from assume-unchanged bit’s. Skip-worktree also takes
367       precedence over assume-unchanged bit when both are set.
368

SPLIT INDEX

370       This mode is designed for repositories with very large indexes, and
371       aims at reducing the time it takes to repeatedly write these indexes.
372
373       In this mode, the index is split into two files, $GIT_DIR/index and
374       $GIT_DIR/sharedindex.<SHA-1>. Changes are accumulated in
375       $GIT_DIR/index, the split index, while the shared index file contains
376       all index entries and stays unchanged.
377
378       All changes in the split index are pushed back to the shared index file
379       when the number of entries in the split index reaches a level specified
380       by the splitIndex.maxPercentChange config variable (see git-config(1)).
381
382       Each time a new shared index file is created, the old shared index
383       files are deleted if their modification time is older than what is
384       specified by the splitIndex.sharedIndexExpire config variable (see git-
385       config(1)).
386
387       To avoid deleting a shared index file that is still used, its
388       modification time is updated to the current time everytime a new split
389       index based on the shared index file is either created or read from.
390

UNTRACKED CACHE

392       This cache is meant to speed up commands that involve determining
393       untracked files such as git status.
394
395       This feature works by recording the mtime of the working tree
396       directories and then omitting reading directories and stat calls
397       against files in those directories whose mtime hasn’t changed. For this
398       to work the underlying operating system and file system must change the
399       st_mtime field of directories if files in the directory are added,
400       modified or deleted.
401
402       You can test whether the filesystem supports that with the
403       --test-untracked-cache option. The --untracked-cache option used to
404       implicitly perform that test in older versions of Git, but that’s no
405       longer the case.
406
407       If you want to enable (or disable) this feature, it is easier to use
408       the core.untrackedCache configuration variable (see git-config(1)) than
409       using the --untracked-cache option to git update-index in each
410       repository, especially if you want to do so across all repositories you
411       use, because you can set the configuration variable to true (or false)
412       in your $HOME/.gitconfig just once and have it affect all repositories
413       you touch.
414
415       When the core.untrackedCache configuration variable is changed, the
416       untracked cache is added to or removed from the index the next time a
417       command reads the index; while when --[no-|force-]untracked-cache are
418       used, the untracked cache is immediately added to or removed from the
419       index.
420
421       Before 2.17, the untracked cache had a bug where replacing a directory
422       with a symlink to another directory could cause it to incorrectly show
423       files tracked by git as untracked. See the "status: add a failing test
424       showing a core.untrackedCache bug" commit to git.git. A workaround for
425       that is (and this might work for other undiscovered bugs in the
426       future):
427
428           $ git -c core.untrackedCache=false status
429
430
431       This bug has also been shown to affect non-symlink cases of replacing a
432       directory with a file when it comes to the internal structures of the
433       untracked cache, but no case has been reported where this resulted in
434       wrong "git status" output.
435
436       There are also cases where existing indexes written by git versions
437       before 2.17 will reference directories that don’t exist anymore,
438       potentially causing many "could not open directory" warnings to be
439       printed on "git status". These are new warnings for existing issues
440       that were previously silently discarded.
441
442       As with the bug described above the solution is to one-off do a "git
443       status" run with core.untrackedCache=false to flush out the leftover
444       bad data.
445

FILE SYSTEM MONITOR

447       This feature is intended to speed up git operations for repos that have
448       large working directories.
449
450       It enables git to work together with a file system monitor (see the
451       "fsmonitor-watchman" section of githooks(5)) that can inform it as to
452       what files have been modified. This enables git to avoid having to
453       lstat() every file to find modified files.
454
455       When used in conjunction with the untracked cache, it can further
456       improve performance by avoiding the cost of scanning the entire working
457       directory looking for new files.
458
459       If you want to enable (or disable) this feature, it is easier to use
460       the core.fsmonitor configuration variable (see git-config(1)) than
461       using the --fsmonitor option to git update-index in each repository,
462       especially if you want to do so across all repositories you use,
463       because you can set the configuration variable in your $HOME/.gitconfig
464       just once and have it affect all repositories you touch.
465
466       When the core.fsmonitor configuration variable is changed, the file
467       system monitor is added to or removed from the index the next time a
468       command reads the index. When --[no-]fsmonitor are used, the file
469       system monitor is immediately added to or removed from the index.
470

CONFIGURATION

472       The command honors core.filemode configuration variable. If your
473       repository is on a filesystem whose executable bits are unreliable,
474       this should be set to false (see git-config(1)). This causes the
475       command to ignore differences in file modes recorded in the index and
476       the file mode on the filesystem if they differ only on executable bit.
477       On such an unfortunate filesystem, you may need to use git update-index
478       --chmod=.
479
480       Quite similarly, if core.symlinks configuration variable is set to
481       false (see git-config(1)), symbolic links are checked out as plain
482       files, and this command does not modify a recorded file mode from
483       symbolic link to regular file.
484
485       The command looks at core.ignorestat configuration variable. See Using
486       "assume unchanged" bit section above.
487
488       The command also looks at core.trustctime configuration variable. It
489       can be useful when the inode change time is regularly modified by
490       something outside Git (file system crawlers and backup systems use
491       ctime for marking files processed) (see git-config(1)).
492
493       The untracked cache extension can be enabled by the core.untrackedCache
494       configuration variable (see git-config(1)).
495

SEE ALSO

497       git-config(1), git-add(1), git-ls-files(1)
498

GIT

500       Part of the git(1) suite
501
502
503
504Git 2.21.0                        02/24/2019               GIT-UPDATE-INDEX(1)
Impressum