]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-update-index.txt
update-index doc: note a fixed bug in the untracked cache
[thirdparty/git.git] / Documentation / git-update-index.txt
CommitLineData
215a7ad1 1git-update-index(1)
2cf565c5 2===================
2cf565c5
DG
3
4NAME
5----
c3f0baac 6git-update-index - Register file contents in the working tree to the index
2cf565c5
DG
7
8
9SYNOPSIS
10--------
f9666adf 11[verse]
b1889c36 12'git update-index'
de5f2bf3
MK
13 [--add] [--remove | --force-remove] [--replace]
14 [--refresh] [-q] [--unmerged] [--ignore-missing]
ec160ae1 15 [(--cacheinfo <mode>,<object>,<file>)...]
5773c9f2 16 [--chmod=(+|-)x]
0460ed2c
FC
17 [--[no-]assume-unchanged]
18 [--[no-]skip-worktree]
780494b1 19 [--[no-]fsmonitor-valid]
5fdeacb0 20 [--ignore-submodules]
bc497127 21 [--[no-]split-index]
eaab83d0 22 [--[no-|test-|force-]untracked-cache]
780494b1 23 [--[no-]fsmonitor]
7099c9c7 24 [--really-refresh] [--unresolve] [--again | -g]
14470c0d 25 [--info-only] [--index-info]
69dec66b 26 [-z] [--stdin] [--index-version <n>]
14470c0d 27 [--verbose]
0adda936 28 [--] [<file>...]
2cf565c5
DG
29
30DESCRIPTION
31-----------
32Modifies the index or directory cache. Each file mentioned is updated
5f3aa197 33into the index and any 'unmerged' or 'needs updating' state is
2cf565c5
DG
34cleared.
35
5162e697 36See also linkgit:git-add[1] for a more user-friendly way to do some of
e701ccc3
MM
37the most common operations on the index.
38
0b444cdb 39The way 'git update-index' handles files it is told about can be modified
2cf565c5
DG
40using the various options:
41
42OPTIONS
43-------
44--add::
5f3aa197 45 If a specified file isn't in the index already then it's
2cf565c5
DG
46 added.
47 Default behaviour is to ignore new files.
48
49--remove::
5f3aa197 50 If a specified file is in the index but is missing then it's
2cf565c5 51 removed.
abda1ef5 52 Default behavior is to ignore removed file.
2cf565c5
DG
53
54--refresh::
5f3aa197 55 Looks at the current index and checks to see if merges or
2cf565c5
DG
56 updates are needed by checking stat() information.
57
14470c0d 58-q::
5f3aa197 59 Quiet. If --refresh finds that the index needs an update, the
14470c0d 60 default behavior is to error out. This option makes
0b444cdb 61 'git update-index' continue anyway.
14470c0d 62
04c8ce9c 63--ignore-submodules::
5fdeacb0
JS
64 Do not try to update submodules. This option is only respected
65 when passed before --refresh.
66
14470c0d 67--unmerged::
5f3aa197 68 If --refresh finds unmerged changes in the index, the default
0b444cdb 69 behavior is to error out. This option makes 'git update-index'
14470c0d
CS
70 continue anyway.
71
2cf565c5
DG
72--ignore-missing::
73 Ignores missing files during a --refresh
74
ec160ae1 75--cacheinfo <mode>,<object>,<path>::
2cf565c5 76--cacheinfo <mode> <object> <path>::
ec160ae1
JH
77 Directly insert the specified info into the index. For
78 backward compatibility, you can also give these three
79 arguments as three separate parameters, but new users are
80 encouraged to use a single-parameter form.
a6080a0a 81
14470c0d 82--index-info::
7acab8f1 83 Read index information from stdin.
14470c0d
CS
84
85--chmod=(+|-)x::
a6080a0a 86 Set the execute permissions on the updated files.
14470c0d 87
0460ed2c 88--[no-]assume-unchanged::
ccadb25f
PO
89 When this flag is specified, the object names recorded
90 for the paths are not updated. Instead, this option
91 sets/unsets the "assume unchanged" bit for the
92 paths. When the "assume unchanged" bit is on, the user
93 promises not to change the file and allows Git to assume
94 that the working tree file matches what is recorded in
95 the index. If you want to change the working tree file,
96 you need to unset the bit to tell Git. This is
f9666adf
JH
97 sometimes helpful when working with a big project on a
98 filesystem that has very slow lstat(2) system call
99 (e.g. cifs).
6259ac66 100+
6259ac66
PB
101Git will fail (gracefully) in case it needs to modify this file
102in the index e.g. when merging in a commit;
103thus, in case the assumed-untracked file is changed upstream,
104you will need to handle the situation manually.
f9666adf 105
466d1f15 106--really-refresh::
bcf9626a 107 Like `--refresh`, but checks stat information unconditionally,
466d1f15
ŠN
108 without regard to the "assume unchanged" setting.
109
0460ed2c 110--[no-]skip-worktree::
44a36913
NTND
111 When one of these flags is specified, the object name recorded
112 for the paths are not updated. Instead, these options
113 set and unset the "skip-worktree" bit for the paths. See
114 section "Skip-worktree bit" below for more information.
115
780494b1
BP
116--[no-]fsmonitor-valid::
117 When one of these flags is specified, the object name recorded
118 for the paths are not updated. Instead, these options
119 set and unset the "fsmonitor valid" bit for the paths. See
120 section "File System Monitor" below for more information.
121
3240240f
SB
122-g::
123--again::
0b444cdb 124 Runs 'git update-index' itself on the paths whose index
83e77a25
JH
125 entries are different from those from the `HEAD` commit.
126
060729dd
MK
127--unresolve::
128 Restores the 'unmerged' or 'needs updating' state of a
129 file during a merge if it was cleared by accident.
130
df6e1516
BL
131--info-only::
132 Do not create objects in the object database for all
133 <file> arguments that follow this flag; just insert
5f3aa197 134 their object IDs into the index.
df6e1516 135
2cf565c5
DG
136--force-remove::
137 Remove the file from the index even when the working directory
9b63f501 138 still has such a file. (Implies --remove.)
2cf565c5
DG
139
140--replace::
141 By default, when a file `path` exists in the index,
0b444cdb 142 'git update-index' refuses an attempt to add `path/file`.
2cf565c5
DG
143 Similarly if a file `path/file` exists, a file `path`
144 cannot be added. With --replace flag, existing entries
04c8ce9c 145 that conflict with the entry being added are
2cf565c5
DG
146 automatically removed with warning messages.
147
1f7f99de
JH
148--stdin::
149 Instead of taking list of paths from the command line,
150 read list of paths from the standard input. Paths are
151 separated by LF (i.e. one path per line) by default.
152
14470c0d
CS
153--verbose::
154 Report what is being added and removed from index.
155
69dec66b
JH
156--index-version <n>::
157 Write the resulting index out in the named on-disk format version.
647d8794
NTND
158 Supported versions are 2, 3 and 4. The current default version is 2
159 or 3, depending on whether extra features are used, such as
160 `git add -N`.
161+
162Version 4 performs a simple pathname compression that reduces index
163size by 30%-50% on large repositories, which results in faster load
be94568b 164time. Version 4 is relatively young (first released in 1.8.0 in
647d8794
NTND
165October 2012). Other Git implementations such as JGit and libgit2
166may not support it yet.
69dec66b 167
1f7f99de 168-z::
537497be
BW
169 Only meaningful with `--stdin` or `--index-info`; paths are
170 separated with NUL character instead of LF.
1f7f99de 171
c18b80a0
NTND
172--split-index::
173--no-split-index::
b4601395
CC
174 Enable or disable split index mode. If split-index mode is
175 already enabled and `--split-index` is given again, all
176 changes in $GIT_DIR/index are pushed back to the shared index
177 file.
13c0e4c4
CC
178+
179These options take effect whatever the value of the `core.splitIndex`
180configuration variable (see linkgit:git-config[1]). But a warning is
181emitted when the change goes against the configured value, as the
182configured value will take effect next time the index is read and this
183will remove the intended effect of the option.
c18b80a0 184
9e597241
NTND
185--untracked-cache::
186--no-untracked-cache::
435ec090
CC
187 Enable or disable untracked cache feature. Please use
188 `--test-untracked-cache` before enabling it.
189+
190These options take effect whatever the value of the `core.untrackedCache`
191configuration variable (see linkgit:git-config[1]). But a warning is
192emitted when the change goes against the configured value, as the
193configured value will take effect next time the index is read and this
194will remove the intended effect of the option.
9e597241 195
eaab83d0
CC
196--test-untracked-cache::
197 Only perform tests on the working directory to make sure
198 untracked cache can be used. You have to manually enable
435ec090
CC
199 untracked cache using `--untracked-cache` or
200 `--force-untracked-cache` or the `core.untrackedCache`
201 configuration variable afterwards if you really want to use
202 it. If a test fails the exit code is 1 and a message
203 explains what is not working as needed, otherwise the exit
204 code is 0 and OK is printed.
eaab83d0 205
f64cb88d 206--force-untracked-cache::
435ec090
CC
207 Same as `--untracked-cache`. Provided for backwards
208 compatibility with older versions of Git where
209 `--untracked-cache` used to imply `--test-untracked-cache` but
210 this option would enable the extension unconditionally.
f64cb88d 211
780494b1
BP
212--fsmonitor::
213--no-fsmonitor::
214 Enable or disable files system monitor feature. These options
215 take effect whatever the value of the `core.fsmonitor`
216 configuration variable (see linkgit:git-config[1]). But a warning
217 is emitted when the change goes against the configured value, as
218 the configured value will take effect next time the index is
219 read and this will remove the intended effect of the option.
220
e994004f 221\--::
2cf565c5
DG
222 Do not interpret any more arguments as options.
223
224<file>::
225 Files to act on.
5773c9f2 226 Note that files beginning with '.' are discarded. This includes
a6080a0a 227 `./file` and `dir/./file`. If you don't want this, then use
2cf565c5
DG
228 cleaner names.
229 The same applies to directories ending '/' and paths with '//'
230
231Using --refresh
232---------------
bcf9626a 233`--refresh` does not calculate a new sha1 file or bring the index
7560f547 234up to date for mode/content changes. But what it *does* do is to
5f3aa197
LS
235"re-match" the stat information of a file with the index, so that you
236can refresh the index for a file that hasn't been changed but where
2cf565c5
DG
237the stat entry is out of date.
238
0b444cdb 239For example, you'd want to do this after doing a 'git read-tree', to link
5f3aa197 240up the stat index details with the proper files.
2cf565c5 241
df6e1516
BL
242Using --cacheinfo or --info-only
243--------------------------------
bcf9626a 244`--cacheinfo` is used to register a file that is not in the
df6e1516
BL
245current working directory. This is useful for minimum-checkout
246merging.
247
df8baa42 248To pretend you have a file with mode and sha1 at path, say:
2cf565c5 249
61f693bd 250----------------
7ac92f64 251$ git update-index --cacheinfo <mode>,<sha1>,<path>
61f693bd 252----------------
2cf565c5 253
bcf9626a 254`--info-only` is used to register files without placing them in the object
df6e1516 255database. This is useful for status-only repositories.
2cf565c5 256
bcf9626a
MM
257Both `--cacheinfo` and `--info-only` behave similarly: the index is updated
258but the object database isn't. `--cacheinfo` is useful when the object is
259in the database but the file isn't available locally. `--info-only` is
df6e1516
BL
260useful when the file is available, but you do not wish to update the
261object database.
262
d23748a6
JH
263
264Using --index-info
265------------------
266
267`--index-info` is a more powerful mechanism that lets you feed
268multiple entry definitions from the standard input, and designed
269specifically for scripts. It can take inputs of three formats:
270
271 . mode SP sha1 TAB path
272+
273The first format is what "git-apply --index-info"
274reports, and used to reconstruct a partial tree
275that is used for phony merge base tree when falling
276back on 3-way merge.
277
278 . mode SP type SP sha1 TAB path
279+
0b444cdb 280The second format is to stuff 'git ls-tree' output
d23748a6
JH
281into the index file.
282
283 . mode SP sha1 SP stage TAB path
284+
285This format is to put higher order stages into the
0b444cdb 286index file and matches 'git ls-files --stage' output.
d23748a6
JH
287
288To place a higher stage entry to the index, the path should
289first be removed by feeding a mode=0 entry for the path, and
290then feeding necessary input lines in the third format.
291
292For example, starting with this index:
293
294------------
295$ git ls-files -s
296100644 8a1218a1024a212bb3db30becd860315f9f3ac52 0 frotz
297------------
298
299you can feed the following input to `--index-info`:
300
301------------
302$ git update-index --index-info
3030 0000000000000000000000000000000000000000 frotz
304100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz
305100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz
306------------
307
308The first line of the input feeds 0 as the mode to remove the
d5fa1f1a 309path; the SHA-1 does not matter as long as it is well formatted.
d23748a6
JH
310Then the second and third line feeds stage 1 and stage 2 entries
311for that path. After the above, we would end up with this:
312
313------------
314$ git ls-files -s
315100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz
316100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz
317------------
318
319
bae777db
JF
320Using ``assume unchanged'' bit
321------------------------------
f9666adf 322
2de9b711 323Many operations in Git depend on your filesystem to have an
f9666adf
JH
324efficient `lstat(2)` implementation, so that `st_mtime`
325information for working tree files can be cheaply checked to see
326if the file contents have changed from the version recorded in
327the index file. Unfortunately, some filesystems have
328inefficient `lstat(2)`. If your filesystem is one of them, you
329can set "assume unchanged" bit to paths you have not changed to
2de9b711
TA
330cause Git not to do this check. Note that setting this bit on a
331path does not mean Git will check the contents of the file to
332see if it has changed -- it makes Git to omit any checking and
f9666adf 333assume it has *not* changed. When you make changes to working
2de9b711 334tree files, you have to explicitly tell Git about it by dropping
f9666adf
JH
335"assume unchanged" bit, either before or after you modify them.
336
337In order to set "assume unchanged" bit, use `--assume-unchanged`
acd6d7e7
SN
338option. To unset, use `--no-assume-unchanged`. To see which files
339have the "assume unchanged" bit set, use `git ls-files -v`
340(see linkgit:git-ls-files[1]).
f9666adf
JH
341
342The command looks at `core.ignorestat` configuration variable. When
b1889c36 343this is true, paths updated with `git update-index paths...` and
2de9b711 344paths updated with other Git commands that update both index and
0b444cdb
TR
345working tree (e.g. 'git apply --index', 'git checkout-index -u',
346and 'git read-tree -u') are automatically marked as "assume
f9666adf 347unchanged". Note that "assume unchanged" bit is *not* set if
b1889c36
JN
348`git update-index --refresh` finds the working tree file matches
349the index (use `git update-index --really-refresh` if you want
f9666adf
JH
350to mark them as "assume unchanged").
351
352
df6e1516
BL
353Examples
354--------
2cf565c5
DG
355To update and refresh only the files already checked out:
356
61f693bd 357----------------
b1889c36 358$ git checkout-index -n -f -a && git update-index --ignore-missing --refresh
61f693bd 359----------------
2cf565c5 360
48aeecdc
SE
361On an inefficient filesystem with `core.ignorestat` set::
362+
f9666adf 363------------
48aeecdc
SE
364$ git update-index --really-refresh <1>
365$ git update-index --no-assume-unchanged foo.c <2>
366$ git diff --name-only <3>
f9666adf 367$ edit foo.c
48aeecdc 368$ git diff --name-only <4>
f9666adf 369M foo.c
48aeecdc
SE
370$ git update-index foo.c <5>
371$ git diff --name-only <6>
f9666adf 372$ edit foo.c
48aeecdc
SE
373$ git diff --name-only <7>
374$ git update-index --no-assume-unchanged foo.c <8>
375$ git diff --name-only <9>
f9666adf 376M foo.c
48aeecdc
SE
377------------
378+
379<1> forces lstat(2) to set "assume unchanged" bits for paths that match index.
f9666adf
JH
380<2> mark the path to be edited.
381<3> this does lstat(2) and finds index matches the path.
48aeecdc 382<4> this does lstat(2) and finds index does *not* match the path.
f9666adf
JH
383<5> registering the new version to index sets "assume unchanged" bit.
384<6> and it is assumed unchanged.
385<7> even after you edit it.
386<8> you can tell about the change after the fact.
387<9> now it checks with lstat(2) and finds it has been changed.
f9666adf 388
2cf565c5 389
44a36913
NTND
390Skip-worktree bit
391-----------------
392
393Skip-worktree bit can be defined in one (long) sentence: When reading
394an entry, if it is marked as skip-worktree, then Git pretends its
395working directory version is up to date and read the index version
396instead.
397
398To elaborate, "reading" means checking for file existence, reading
399file attributes or file content. The working directory version may be
400present or absent. If present, its content may match against the index
401version or not. Writing is not affected by this bit, content safety
402is still first priority. Note that Git _can_ update working directory
403file, that is marked skip-worktree, if it is safe to do so (i.e.
404working directory version matches index version)
405
406Although this bit looks similar to assume-unchanged bit, its goal is
407different from assume-unchanged bit's. Skip-worktree also takes
408precedence over assume-unchanged bit when both are set.
409
b4601395
CC
410Split index
411-----------
412
413This mode is designed for repositories with very large indexes, and
414aims at reducing the time it takes to repeatedly write these indexes.
415
416In this mode, the index is split into two files, $GIT_DIR/index and
417$GIT_DIR/sharedindex.<SHA-1>. Changes are accumulated in
418$GIT_DIR/index, the split index, while the shared index file contains
419all index entries and stays unchanged.
420
421All changes in the split index are pushed back to the shared index
422file when the number of entries in the split index reaches a level
423specified by the splitIndex.maxPercentChange config variable (see
424linkgit:git-config[1]).
425
426Each time a new shared index file is created, the old shared index
427files are deleted if their modification time is older than what is
428specified by the splitIndex.sharedIndexExpire config variable (see
429linkgit:git-config[1]).
430
431To avoid deleting a shared index file that is still used, its
432modification time is updated to the current time everytime a new split
433index based on the shared index file is either created or read from.
434
435ec090
CC
435Untracked cache
436---------------
437
438This cache is meant to speed up commands that involve determining
439untracked files such as `git status`.
440
441This feature works by recording the mtime of the working tree
442directories and then omitting reading directories and stat calls
443against files in those directories whose mtime hasn't changed. For
444this to work the underlying operating system and file system must
445change the `st_mtime` field of directories if files in the directory
446are added, modified or deleted.
447
448You can test whether the filesystem supports that with the
449`--test-untracked-cache` option. The `--untracked-cache` option used
450to implicitly perform that test in older versions of Git, but that's
451no longer the case.
452
453If you want to enable (or disable) this feature, it is easier to use
454the `core.untrackedCache` configuration variable (see
455linkgit:git-config[1]) than using the `--untracked-cache` option to
456`git update-index` in each repository, especially if you want to do so
457across all repositories you use, because you can set the configuration
458variable to `true` (or `false`) in your `$HOME/.gitconfig` just once
459and have it affect all repositories you touch.
460
461When the `core.untrackedCache` configuration variable is changed, the
462untracked cache is added to or removed from the index the next time a
463command reads the index; while when `--[no-|force-]untracked-cache`
464are used, the untracked cache is immediately added to or removed from
465the index.
44a36913 466
9b978691
ÆAB
467Before 2.17, the untracked cache had a bug where replacing a directory
468with a symlink to another directory could cause it to incorrectly show
469files tracked by git as untracked. See the "status: add a failing test
470showing a core.untrackedCache bug" commit to git.git. A workaround for
471that is (and this might work for other undiscovered bugs in the
472future):
473
474----------------
475$ git -c core.untrackedCache=false status
476----------------
477
478This bug has also been shown to affect non-symlink cases of replacing
479a directory with a file when it comes to the internal structures of
480the untracked cache, but no case has been reported where this resulted in
481wrong "git status" output.
482
780494b1
BP
483File System Monitor
484-------------------
485
486This feature is intended to speed up git operations for repos that have
487large working directories.
488
489It enables git to work together with a file system monitor (see the
490"fsmonitor-watchman" section of linkgit:githooks[5]) that can
491inform it as to what files have been modified. This enables git to avoid
492having to lstat() every file to find modified files.
493
494When used in conjunction with the untracked cache, it can further improve
495performance by avoiding the cost of scanning the entire working directory
496looking for new files.
497
498If you want to enable (or disable) this feature, it is easier to use
499the `core.fsmonitor` configuration variable (see
500linkgit:git-config[1]) than using the `--fsmonitor` option to
501`git update-index` in each repository, especially if you want to do so
502across all repositories you use, because you can set the configuration
503variable to `true` (or `false`) in your `$HOME/.gitconfig` just once
504and have it affect all repositories you touch.
505
506When the `core.fsmonitor` configuration variable is changed, the
507file system monitor is added to or removed from the index the next time
508a command reads the index. When `--[no-]fsmonitor` are used, the file
509system monitor is immediately added to or removed from the index.
510
5773c9f2
JH
511Configuration
512-------------
513
514The command honors `core.filemode` configuration variable. If
466d1f15 515your repository is on a filesystem whose executable bits are
5162e697 516unreliable, this should be set to 'false' (see linkgit:git-config[1]).
61f693bd
JL
517This causes the command to ignore differences in file modes recorded
518in the index and the file mode on the filesystem if they differ only on
5773c9f2 519executable bit. On such an unfortunate filesystem, you may
0b444cdb 520need to use 'git update-index --chmod='.
5773c9f2 521
78a8d641 522Quite similarly, if `core.symlinks` configuration variable is set
5162e697 523to 'false' (see linkgit:git-config[1]), symbolic links are checked out
78a8d641
JS
524as plain files, and this command does not modify a recorded file mode
525from symbolic link to regular file.
526
f9666adf
JH
527The command looks at `core.ignorestat` configuration variable. See
528'Using "assume unchanged" bit' section above.
529
1ce4790b
AR
530The command also looks at `core.trustctime` configuration variable.
531It can be useful when the inode change time is regularly modified by
532something outside Git (file system crawlers and backup systems use
533ctime for marking files processed) (see linkgit:git-config[1]).
534
435ec090
CC
535The untracked cache extension can be enabled by the
536`core.untrackedCache` configuration variable (see
537linkgit:git-config[1]).
61f693bd 538
56ae8df5 539SEE ALSO
61f693bd 540--------
5162e697 541linkgit:git-config[1],
acd6d7e7
SN
542linkgit:git-add[1],
543linkgit:git-ls-files[1]
61f693bd 544
2cf565c5
DG
545GIT
546---
9e1f0a85 547Part of the linkgit:git[1] suite