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 with mode and sha1 at path, say:
229
230           $ git update-index --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 sha1 TAB path
248
249           The first format is what "git-apply --index-info" reports, and used
250           to reconstruct a partial tree that is used for phony merge base
251           tree when falling back on 3-way merge.
252
253        2. mode SP type SP sha1 TAB path
254
255           The second format is to stuff git ls-tree output into the index
256           file.
257
258        3. mode SP sha1 SP stage TAB path
259
260           This format is to put higher order stages into the index file and
261           matches git ls-files --stage output.
262
263       To place a higher stage entry to the index, the path should first be
264       removed by feeding a mode=0 entry for the path, and then feeding
265       necessary input lines in the third format.
266
267       For example, starting with this index:
268
269           $ git ls-files -s
270           100644 8a1218a1024a212bb3db30becd860315f9f3ac52 0       frotz
271
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
281       The first line of the input feeds 0 as the mode to remove the path; the
282       SHA-1 does not matter as long as it is well formatted. Then the second
283       and third line feeds stage 1 and stage 2 entries for that path. After
284       the above, we would end up with this:
285
286           $ git ls-files -s
287           100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1       frotz
288           100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2       frotz
289
290

USING “ASSUME UNCHANGED” BIT

292       Many operations in Git depend on your filesystem to have an efficient
293       lstat(2) implementation, so that st_mtime information for working tree
294       files can be cheaply checked to see if the file contents have changed
295       from the version recorded in the index file. Unfortunately, some
296       filesystems have inefficient lstat(2). If your filesystem is one of
297       them, you can set "assume unchanged" bit to paths you have not changed
298       to cause Git not to do this check. Note that setting this bit on a path
299       does not mean Git will check the contents of the file to see if it has
300       changed — it makes Git to omit any checking and assume it has not
301       changed. When you make changes to working tree files, you have to
302       explicitly tell Git about it by dropping "assume unchanged" bit, either
303       before or after you modify them.
304
305       In order to set "assume unchanged" bit, use --assume-unchanged option.
306       To unset, use --no-assume-unchanged. To see which files have the
307       "assume unchanged" bit set, use git ls-files -v (see git-ls-files(1)).
308
309       The command looks at core.ignorestat configuration variable. When this
310       is true, paths updated with git update-index paths... and paths updated
311       with other Git commands that update both index and working tree (e.g.
312       git apply --index, git checkout-index -u, and git read-tree -u) are
313       automatically marked as "assume unchanged". Note that "assume
314       unchanged" bit is not set if git update-index --refresh finds the
315       working tree file matches the index (use git update-index
316       --really-refresh if you want to mark them as "assume unchanged").
317

EXAMPLES

319       To update and refresh only the files already checked out:
320
321           $ git checkout-index -n -f -a && git update-index --ignore-missing --refresh
322
323
324
325       On an inefficient filesystem with core.ignorestat set
326
327               $ git update-index --really-refresh              (1)
328               $ git update-index --no-assume-unchanged foo.c   (2)
329               $ git diff --name-only                           (3)
330               $ edit foo.c
331               $ git diff --name-only                           (4)
332               M foo.c
333               $ git update-index foo.c                         (5)
334               $ git diff --name-only                           (6)
335               $ edit foo.c
336               $ git diff --name-only                           (7)
337               $ git update-index --no-assume-unchanged foo.c   (8)
338               $ git diff --name-only                           (9)
339               M foo.c
340
341           1. forces lstat(2) to set "assume unchanged" bits for paths that
342           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 path.
346           5. registering the new version to index sets "assume unchanged"
347           bit.
348           6. and it is assumed unchanged.
349           7. even after you edit it.
350           8. you can tell about the change after the fact.
351           9. now it checks with lstat(2) and finds it has been changed.
352

SKIP-WORKTREE BIT

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

SPLIT INDEX

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

UNTRACKED CACHE

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

FILE SYSTEM MONITOR

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

CONFIGURATION

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

SEE ALSO

499       git-config(1), git-add(1), git-ls-files(1)
500

GIT

502       Part of the git(1) suite
503
504
505
506Git 2.18.1                        05/14/2019               GIT-UPDATE-INDEX(1)
Impressum