Merge branch 'gt/unit-test-strcmp-offset'
[git.git] / Documentation / git-update-index.txt
blob7128aed540581f37a8e06dec79ea720e3cfacd8c
1 git-update-index(1)
2 ===================
4 NAME
5 ----
6 git-update-index - Register file contents in the working tree to the index
9 SYNOPSIS
10 --------
11 [verse]
12 'git update-index'
13              [--add] [--remove | --force-remove] [--replace]
14              [--refresh] [-q] [--unmerged] [--ignore-missing]
15              [(--cacheinfo <mode>,<object>,<file>)...]
16              [--chmod=(+|-)x]
17              [--[no-]assume-unchanged]
18              [--[no-]skip-worktree]
19              [--[no-]ignore-skip-worktree-entries]
20              [--[no-]fsmonitor-valid]
21              [--ignore-submodules]
22              [--[no-]split-index]
23              [--[no-|test-|force-]untracked-cache]
24              [--[no-]fsmonitor]
25              [--really-refresh] [--unresolve] [--again | -g]
26              [--info-only] [--index-info]
27              [-z] [--stdin] [--index-version <n>]
28              [--show-index-version]
29              [--verbose]
30              [--] [<file>...]
32 DESCRIPTION
33 -----------
34 Modifies the index. Each file mentioned is updated into the index and
35 any 'unmerged' or 'needs updating' state is cleared.
37 See also linkgit:git-add[1] for a more user-friendly way to do some of
38 the most common operations on the index.
40 The way 'git update-index' handles files it is told about can be modified
41 using the various options:
43 OPTIONS
44 -------
45 --add::
46         If a specified file isn't in the index already then it's
47         added.
48         Default behaviour is to ignore new files.
50 --remove::
51         If a specified file is in the index but is missing then it's
52         removed.
53         Default behavior is to ignore removed files.
55 --refresh::
56         Looks at the current index and checks to see if merges or
57         updates are needed by checking stat() information.
59 -q::
60         Quiet.  If --refresh finds that the index needs an update, the
61         default behavior is to error out.  This option makes
62         'git update-index' continue anyway.
64 --ignore-submodules::
65         Do not try to update submodules.  This option is only respected
66         when passed before --refresh.
68 --unmerged::
69         If --refresh finds unmerged changes in the index, the default
70         behavior is to error out.  This option makes 'git update-index'
71         continue anyway.
73 --ignore-missing::
74         Ignores missing files during a --refresh
76 --cacheinfo <mode>,<object>,<path>::
77 --cacheinfo <mode> <object> <path>::
78         Directly insert the specified info into the index.  For
79         backward compatibility, you can also give these three
80         arguments as three separate parameters, but new users are
81         encouraged to use a single-parameter form.
83 --index-info::
84         Read index information from stdin.
86 --chmod=(+|-)x::
87         Set the execute permissions on the updated files.
89 --[no-]assume-unchanged::
90         When this flag is specified, the object names recorded
91         for the paths are not updated.  Instead, this option
92         sets/unsets the "assume unchanged" bit for the
93         paths.  When the "assume unchanged" bit is on, the user
94         promises not to change the file and allows Git to assume
95         that the working tree file matches what is recorded in
96         the index.  If you want to change the working tree file,
97         you need to unset the bit to tell Git.  This is
98         sometimes helpful when working with a big project on a
99         filesystem that has a very slow lstat(2) system call
100         (e.g. cifs).
102 Git will fail (gracefully) in case it needs to modify this file
103 in the index e.g. when merging in a commit;
104 thus, in case the assumed-untracked file is changed upstream,
105 you will need to handle the situation manually.
107 --really-refresh::
108         Like `--refresh`, but checks stat information unconditionally,
109         without regard to the "assume unchanged" setting.
111 --[no-]skip-worktree::
112         When one of these flags is specified, the object names recorded
113         for the paths are not updated. Instead, these options
114         set and unset the "skip-worktree" bit for the paths. See
115         section "Skip-worktree bit" below for more information.
118 --[no-]ignore-skip-worktree-entries::
119         Do not remove skip-worktree (AKA "index-only") entries even when
120         the `--remove` option was specified.
122 --[no-]fsmonitor-valid::
123         When one of these flags is specified, the object names recorded
124         for the paths are not updated. Instead, these options
125         set and unset the "fsmonitor valid" bit for the paths. See
126         section "File System Monitor" below for more information.
128 -g::
129 --again::
130         Runs 'git update-index' itself on the paths whose index
131         entries are different from those of the `HEAD` commit.
133 --unresolve::
134         Restores the 'unmerged' or 'needs updating' state of a
135         file during a merge if it was cleared by accident.
137 --info-only::
138         Do not create objects in the object database for all
139         <file> arguments that follow this flag; just insert
140         their object IDs into the index.
142 --force-remove::
143         Remove the file from the index even when the working directory
144         still has such a file. (Implies --remove.)
146 --replace::
147         By default, when a file `path` exists in the index,
148         'git update-index' refuses an attempt to add `path/file`.
149         Similarly if a file `path/file` exists, a file `path`
150         cannot be added.  With --replace flag, existing entries
151         that conflict with the entry being added are
152         automatically removed with warning messages.
154 --stdin::
155         Instead of taking a list of paths from the command line,
156         read a list of paths from the standard input.  Paths are
157         separated by LF (i.e. one path per line) by default.
159 --verbose::
160         Report what is being added and removed from the index.
162 --index-version <n>::
163         Write the resulting index out in the named on-disk format version.
164         Supported versions are 2, 3, and 4. The current default version is 2
165         or 3, depending on whether extra features are used, such as
166         `git add -N`.  With `--verbose`, also report the version the index
167         file uses before and after this command.
169 Version 4 performs a simple pathname compression that reduces index
170 size by 30%-50% on large repositories, which results in faster load
171 time.  Git supports it since version 1.8.0, released in October 2012,
172 and support for it was added to libgit2 in 2016 and to JGit in 2020.
173 Older versions of this manual page called it "relatively young", but
174 it should be considered mature technology these days.
176 --show-index-version::
177         Report the index format version used by the on-disk index file.
178         See `--index-version` above.
180 -z::
181         Only meaningful with `--stdin` or `--index-info`; paths are
182         separated with NUL character instead of LF.
184 --split-index::
185 --no-split-index::
186         Enable or disable split index mode. If split-index mode is
187         already enabled and `--split-index` is given again, all
188         changes in $GIT_DIR/index are pushed back to the shared index
189         file.
191 These options take effect whatever the value of the `core.splitIndex`
192 configuration variable (see linkgit:git-config[1]). But a warning is
193 emitted when the change goes against the configured value, as the
194 configured value will take effect next time the index is read and this
195 will remove the intended effect of the option.
197 --untracked-cache::
198 --no-untracked-cache::
199         Enable or disable untracked cache feature. Please use
200         `--test-untracked-cache` before enabling it.
202 These options take effect whatever the value of the `core.untrackedCache`
203 configuration variable (see linkgit:git-config[1]). But a warning is
204 emitted when the change goes against the configured value, as the
205 configured value will take effect next time the index is read and this
206 will remove the intended effect of the option.
208 --test-untracked-cache::
209         Only perform tests on the working directory to make sure
210         untracked cache can be used. You have to manually enable
211         untracked cache using `--untracked-cache` or
212         `--force-untracked-cache` or the `core.untrackedCache`
213         configuration variable afterwards if you really want to use
214         it. If a test fails the exit code is 1 and a message
215         explains what is not working as needed, otherwise the exit
216         code is 0 and OK is printed.
218 --force-untracked-cache::
219         Same as `--untracked-cache`. Provided for backwards
220         compatibility with older versions of Git where
221         `--untracked-cache` used to imply `--test-untracked-cache` but
222         this option would enable the extension unconditionally.
224 --fsmonitor::
225 --no-fsmonitor::
226         Enable or disable files system monitor feature. These options
227         take effect whatever the value of the `core.fsmonitor`
228         configuration variable (see linkgit:git-config[1]). But a warning
229         is emitted when the change goes against the configured value, as
230         the configured value will take effect next time the index is
231         read and this will remove the intended effect of the option.
233 \--::
234         Do not interpret any more arguments as options.
236 <file>::
237         Files to act on.
238         Note that files beginning with '.' are discarded. This includes
239         `./file` and `dir/./file`. If you don't want this, then use
240         cleaner names.
241         The same applies to directories ending '/' and paths with '//'
243 USING --REFRESH
244 ---------------
245 `--refresh` does not calculate a new sha1 file or bring the index
246 up to date for mode/content changes. But what it *does* do is to
247 "re-match" the stat information of a file with the index, so that you
248 can refresh the index for a file that hasn't been changed but where
249 the stat entry is out of date.
251 For example, you'd want to do this after doing a 'git read-tree', to link
252 up the stat index details with the proper files.
254 USING --CACHEINFO OR --INFO-ONLY
255 --------------------------------
256 `--cacheinfo` is used to register a file that is not in the
257 current working directory.  This is useful for minimum-checkout
258 merging.
260 To pretend you have a file at path with mode and sha1, say:
262 ----------------
263 $ git update-index --add --cacheinfo <mode>,<sha1>,<path>
264 ----------------
266 `--info-only` is used to register files without placing them in the object
267 database.  This is useful for status-only repositories.
269 Both `--cacheinfo` and `--info-only` behave similarly: the index is updated
270 but the object database isn't.  `--cacheinfo` is useful when the object is
271 in the database but the file isn't available locally.  `--info-only` is
272 useful when the file is available, but you do not wish to update the
273 object database.
276 USING --INDEX-INFO
277 ------------------
279 `--index-info` is a more powerful mechanism that lets you feed
280 multiple entry definitions from the standard input, and designed
281 specifically for scripts.  It can take inputs of three formats:
283     . mode SP type SP sha1          TAB path
285 This format is to stuff `git ls-tree` output into the index.
287     . mode         SP sha1 SP stage TAB path
289 This format is to put higher order stages into the
290 index file and matches 'git ls-files --stage' output.
292     . mode         SP sha1          TAB path
294 This format is no longer produced by any Git command, but is
295 and will continue to be supported by `update-index --index-info`.
297 To place a higher stage entry to the index, the path should
298 first be removed by feeding a mode=0 entry for the path, and
299 then feeding necessary input lines in the third format.
301 For example, starting with this index:
303 ------------
304 $ git ls-files -s
305 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 0       frotz
306 ------------
308 you can feed the following input to `--index-info`:
310 ------------
311 $ git update-index --index-info
312 0 0000000000000000000000000000000000000000      frotz
313 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1       frotz
314 100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2       frotz
315 ------------
317 The first line of the input feeds 0 as the mode to remove the
318 path; the SHA-1 does not matter as long as it is well formatted.
319 Then the second and third line feeds stage 1 and stage 2 entries
320 for that path.  After the above, we would end up with this:
322 ------------
323 $ git ls-files -s
324 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1       frotz
325 100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2       frotz
326 ------------
329 USING ``ASSUME UNCHANGED'' BIT
330 ------------------------------
332 Many operations in Git depend on your filesystem to have an
333 efficient `lstat(2)` implementation, so that `st_mtime`
334 information for working tree files can be cheaply checked to see
335 if the file contents have changed from the version recorded in
336 the index file.  Unfortunately, some filesystems have
337 inefficient `lstat(2)`.  If your filesystem is one of them, you
338 can set "assume unchanged" bit to paths you have not changed to
339 cause Git not to do this check.  Note that setting this bit on a
340 path does not mean Git will check the contents of the file to
341 see if it has changed -- it makes Git to omit any checking and
342 assume it has *not* changed.  When you make changes to working
343 tree files, you have to explicitly tell Git about it by dropping
344 "assume unchanged" bit, either before or after you modify them.
346 In order to set "assume unchanged" bit, use `--assume-unchanged`
347 option.  To unset, use `--no-assume-unchanged`. To see which files
348 have the "assume unchanged" bit set, use `git ls-files -v`
349 (see linkgit:git-ls-files[1]).
351 The command looks at `core.ignorestat` configuration variable.  When
352 this is true, paths updated with `git update-index paths...` and
353 paths updated with other Git commands that update both index and
354 working tree (e.g. 'git apply --index', 'git checkout-index -u',
355 and 'git read-tree -u') are automatically marked as "assume
356 unchanged".  Note that "assume unchanged" bit is *not* set if
357 `git update-index --refresh` finds the working tree file matches
358 the index (use `git update-index --really-refresh` if you want
359 to mark them as "assume unchanged").
361 Sometimes users confuse the assume-unchanged bit with the
362 skip-worktree bit.  See the final paragraph in the "Skip-worktree bit"
363 section below for an explanation of the differences.
366 EXAMPLES
367 --------
368 To update and refresh only the files already checked out:
370 ----------------
371 $ git checkout-index -n -f -a && git update-index --ignore-missing --refresh
372 ----------------
374 On an inefficient filesystem with `core.ignorestat` set::
376 ------------
377 $ git update-index --really-refresh              <1>
378 $ git update-index --no-assume-unchanged foo.c   <2>
379 $ git diff --name-only                           <3>
380 $ edit foo.c
381 $ git diff --name-only                           <4>
382 M foo.c
383 $ git update-index foo.c                         <5>
384 $ git diff --name-only                           <6>
385 $ edit foo.c
386 $ git diff --name-only                           <7>
387 $ git update-index --no-assume-unchanged foo.c   <8>
388 $ git diff --name-only                           <9>
389 M foo.c
390 ------------
392 <1> forces lstat(2) to set "assume unchanged" bits for paths that match index.
393 <2> mark the path to be edited.
394 <3> this does lstat(2) and finds index matches the path.
395 <4> this does lstat(2) and finds index does *not* match the path.
396 <5> registering the new version to index sets "assume unchanged" bit.
397 <6> and it is assumed unchanged.
398 <7> even after you edit it.
399 <8> you can tell about the change after the fact.
400 <9> now it checks with lstat(2) and finds it has been changed.
403 SKIP-WORKTREE BIT
404 -----------------
406 Skip-worktree bit can be defined in one (long) sentence: Tell git to
407 avoid writing the file to the working directory when reasonably
408 possible, and treat the file as unchanged when it is not
409 present in the working directory.
411 Note that not all git commands will pay attention to this bit, and
412 some only partially support it.
414 The update-index flags and the read-tree capabilities relating to the
415 skip-worktree bit predated the introduction of the
416 linkgit:git-sparse-checkout[1] command, which provides a much easier
417 way to configure and handle the skip-worktree bits.  If you want to
418 reduce your working tree to only deal with a subset of the files in
419 the repository, we strongly encourage the use of
420 linkgit:git-sparse-checkout[1] in preference to the low-level
421 update-index and read-tree primitives.
423 The primary purpose of the skip-worktree bit is to enable sparse
424 checkouts, i.e. to have working directories with only a subset of
425 paths present.  When the skip-worktree bit is set, Git commands (such
426 as `switch`, `pull`, `merge`) will avoid writing these files.
427 However, these commands will sometimes write these files anyway in
428 important cases such as conflicts during a merge or rebase.  Git
429 commands will also avoid treating the lack of such files as an
430 intentional deletion; for example `git add -u` will not stage a
431 deletion for these files and `git commit -a` will not make a commit
432 deleting them either.
434 Although this bit looks similar to assume-unchanged bit, its goal is
435 different.  The assume-unchanged bit is for leaving the file in the
436 working tree but having Git omit checking it for changes and presuming
437 that the file has not been changed (though if it can determine without
438 stat'ing the file that it has changed, it is free to record the
439 changes).  skip-worktree tells Git to ignore the absence of the file,
440 avoid updating it when possible with commands that normally update
441 much of the working directory (e.g. `checkout`, `switch`, `pull`,
442 etc.), and not have its absence be recorded in commits.  Note that in
443 sparse checkouts (setup by `git sparse-checkout` or by configuring
444 core.sparseCheckout to true), if a file is marked as skip-worktree in
445 the index but is found in the working tree, Git will clear the
446 skip-worktree bit for that file.
448 SPLIT INDEX
449 -----------
451 This mode is designed for repositories with very large indexes, and
452 aims at reducing the time it takes to repeatedly write these indexes.
454 In this mode, the index is split into two files, $GIT_DIR/index and
455 $GIT_DIR/sharedindex.<SHA-1>. Changes are accumulated in
456 $GIT_DIR/index, the split index, while the shared index file contains
457 all index entries and stays unchanged.
459 All changes in the split index are pushed back to the shared index
460 file when the number of entries in the split index reaches a level
461 specified by the splitIndex.maxPercentChange config variable (see
462 linkgit:git-config[1]).
464 Each time a new shared index file is created, the old shared index
465 files are deleted if their modification time is older than what is
466 specified by the splitIndex.sharedIndexExpire config variable (see
467 linkgit:git-config[1]).
469 To avoid deleting a shared index file that is still used, its
470 modification time is updated to the current time every time a new split
471 index based on the shared index file is either created or read from.
473 UNTRACKED CACHE
474 ---------------
476 This cache is meant to speed up commands that involve determining
477 untracked files such as `git status`.
479 This feature works by recording the mtime of the working tree
480 directories and then omitting reading directories and stat calls
481 against files in those directories whose mtime hasn't changed. For
482 this to work the underlying operating system and file system must
483 change the `st_mtime` field of directories if files in the directory
484 are added, modified or deleted.
486 You can test whether the filesystem supports that with the
487 `--test-untracked-cache` option. The `--untracked-cache` option used
488 to implicitly perform that test in older versions of Git, but that's
489 no longer the case.
491 If you want to enable (or disable) this feature, it is easier to use
492 the `core.untrackedCache` configuration variable (see
493 linkgit:git-config[1]) than using the `--untracked-cache` option to
494 `git update-index` in each repository, especially if you want to do so
495 across all repositories you use, because you can set the configuration
496 variable to `true` (or `false`) in your `$HOME/.gitconfig` just once
497 and have it affect all repositories you touch.
499 When the `core.untrackedCache` configuration variable is changed, the
500 untracked cache is added to or removed from the index the next time a
501 command reads the index; while when `--[no-|force-]untracked-cache`
502 are used, the untracked cache is immediately added to or removed from
503 the index.
505 Before 2.17, the untracked cache had a bug where replacing a directory
506 with a symlink to another directory could cause it to incorrectly show
507 files tracked by git as untracked. See the "status: add a failing test
508 showing a core.untrackedCache bug" commit to git.git. A workaround for
509 that is (and this might work for other undiscovered bugs in the
510 future):
512 ----------------
513 $ git -c core.untrackedCache=false status
514 ----------------
516 This bug has also been shown to affect non-symlink cases of replacing
517 a directory with a file when it comes to the internal structures of
518 the untracked cache, but no case has been reported where this resulted in
519 wrong "git status" output.
521 There are also cases where existing indexes written by git versions
522 before 2.17 will reference directories that don't exist anymore,
523 potentially causing many "could not open directory" warnings to be
524 printed on "git status". These are new warnings for existing issues
525 that were previously silently discarded.
527 As with the bug described above the solution is to one-off do a "git
528 status" run with `core.untrackedCache=false` to flush out the leftover
529 bad data.
531 FILE SYSTEM MONITOR
532 -------------------
534 This feature is intended to speed up git operations for repos that have
535 large working directories.
537 It enables git to work together with a file system monitor (see
538 linkgit:git-fsmonitor{litdd}daemon[1]
539 and the
540 "fsmonitor-watchman" section of linkgit:githooks[5]) that can
541 inform it as to what files have been modified. This enables git to avoid
542 having to lstat() every file to find modified files.
544 When used in conjunction with the untracked cache, it can further improve
545 performance by avoiding the cost of scanning the entire working directory
546 looking for new files.
548 If you want to enable (or disable) this feature, it is easier to use
549 the `core.fsmonitor` configuration variable (see
550 linkgit:git-config[1]) than using the `--fsmonitor` option to `git
551 update-index` in each repository, especially if you want to do so
552 across all repositories you use, because you can set the configuration
553 variable in your `$HOME/.gitconfig` just once and have it affect all
554 repositories you touch.
556 When the `core.fsmonitor` configuration variable is changed, the
557 file system monitor is added to or removed from the index the next time
558 a command reads the index. When `--[no-]fsmonitor` are used, the file
559 system monitor is immediately added to or removed from the index.
561 CONFIGURATION
562 -------------
564 The command honors `core.filemode` configuration variable.  If
565 your repository is on a filesystem whose executable bits are
566 unreliable, this should be set to 'false' (see linkgit:git-config[1]).
567 This causes the command to ignore differences in file modes recorded
568 in the index and the file mode on the filesystem if they differ only on
569 executable bit.   On such an unfortunate filesystem, you may
570 need to use 'git update-index --chmod='.
572 Quite similarly, if `core.symlinks` configuration variable is set
573 to 'false' (see linkgit:git-config[1]), symbolic links are checked out
574 as plain files, and this command does not modify a recorded file mode
575 from symbolic link to regular file.
577 The command looks at `core.ignorestat` configuration variable.  See
578 'Using "assume unchanged" bit' section above.
580 The command also looks at `core.trustctime` configuration variable.
581 It can be useful when the inode change time is regularly modified by
582 something outside Git (file system crawlers and backup systems use
583 ctime for marking files processed) (see linkgit:git-config[1]).
585 The untracked cache extension can be enabled by the
586 `core.untrackedCache` configuration variable (see
587 linkgit:git-config[1]).
589 NOTES
590 -----
592 Users often try to use the assume-unchanged and skip-worktree bits
593 to tell Git to ignore changes to files that are tracked.  This does not
594 work as expected, since Git may still check working tree files against
595 the index when performing certain operations.  In general, Git does not
596 provide a way to ignore changes to tracked files, so alternate solutions
597 are recommended.
599 For example, if the file you want to change is some sort of config file,
600 the repository can include a sample config file that can then be copied
601 into the ignored name and modified.  The repository can even include a
602 script to treat the sample file as a template, modifying and copying it
603 automatically.
605 SEE ALSO
606 --------
607 linkgit:git-config[1],
608 linkgit:git-add[1],
609 linkgit:git-ls-files[1]
613 Part of the linkgit:git[1] suite