2 .\" Title: git-update-index
3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
7 .\" Source: Git 2.34.1.182.ge773545c7f
10 .TH "GIT\-UPDATE\-INDEX" "1" "12/10/2021" "Git 2\&.34\&.1\&.182\&.ge77354" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 git-update-index \- Register file contents in the working tree to the index
35 \fIgit update\-index\fR
36 [\-\-add] [\-\-remove | \-\-force\-remove] [\-\-replace]
37 [\-\-refresh] [\-q] [\-\-unmerged] [\-\-ignore\-missing]
38 [(\-\-cacheinfo <mode>,<object>,<file>)\&...]
40 [\-\-[no\-]assume\-unchanged]
41 [\-\-[no\-]skip\-worktree]
42 [\-\-[no\-]ignore\-skip\-worktree\-entries]
43 [\-\-[no\-]fsmonitor\-valid]
44 [\-\-ignore\-submodules]
45 [\-\-[no\-]split\-index]
46 [\-\-[no\-|test\-|force\-]untracked\-cache]
48 [\-\-really\-refresh] [\-\-unresolve] [\-\-again | \-g]
49 [\-\-info\-only] [\-\-index\-info]
50 [\-z] [\-\-stdin] [\-\-index\-version <n>]
57 Modifies the index\&. Each file mentioned is updated into the index and any \fIunmerged\fR or \fIneeds updating\fR state is cleared\&.
59 See also \fBgit-add\fR(1) for a more user\-friendly way to do some of the most common operations on the index\&.
61 The way \fIgit update\-index\fR handles files it is told about can be modified using the various options:
66 If a specified file isn\(cqt in the index already then it\(cqs added\&. Default behaviour is to ignore new files\&.
71 If a specified file is in the index but is missing then it\(cqs removed\&. Default behavior is to ignore removed file\&.
76 Looks at the current index and checks to see if merges or updates are needed by checking stat() information\&.
81 Quiet\&. If \-\-refresh finds that the index needs an update, the default behavior is to error out\&. This option makes
82 \fIgit update\-index\fR
86 \-\-ignore\-submodules
88 Do not try to update submodules\&. This option is only respected when passed before \-\-refresh\&.
93 If \-\-refresh finds unmerged changes in the index, the default behavior is to error out\&. This option makes
94 \fIgit update\-index\fR
100 Ignores missing files during a \-\-refresh
103 \-\-cacheinfo <mode>,<object>,<path>, \-\-cacheinfo <mode> <object> <path>
105 Directly insert the specified info into the index\&. For backward compatibility, you can also give these three arguments as three separate parameters, but new users are encouraged to use a single\-parameter form\&.
110 Read index information from stdin\&.
115 Set the execute permissions on the updated files\&.
118 \-\-[no\-]assume\-unchanged
120 When this flag is specified, the object names recorded for the paths are not updated\&. Instead, this option sets/unsets the "assume unchanged" bit for the paths\&. When the "assume unchanged" bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index\&. If you want to change the working tree file, you need to unset the bit to tell Git\&. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e\&.g\&. cifs)\&.
122 Git will fail (gracefully) in case it needs to modify this file in the index e\&.g\&. when merging in a commit; thus, in case the assumed\-untracked file is changed upstream, you will need to handle the situation manually\&.
128 \fB\-\-refresh\fR, but checks stat information unconditionally, without regard to the "assume unchanged" setting\&.
131 \-\-[no\-]skip\-worktree
133 When one of these flags is specified, the object name recorded for the paths are not updated\&. Instead, these options set and unset the "skip\-worktree" bit for the paths\&. See section "Skip\-worktree bit" below for more information\&.
136 \-\-[no\-]ignore\-skip\-worktree\-entries
138 Do not remove skip\-worktree (AKA "index\-only") entries even when the
140 option was specified\&.
143 \-\-[no\-]fsmonitor\-valid
145 When one of these flags is specified, the object name recorded for the paths are not updated\&. Instead, these options set and unset the "fsmonitor valid" bit for the paths\&. See section "File System Monitor" below for more information\&.
151 \fIgit update\-index\fR
152 itself on the paths whose index entries are different from those from the
163 state of a file during a merge if it was cleared by accident\&.
168 Do not create objects in the object database for all <file> arguments that follow this flag; just insert their object IDs into the index\&.
173 Remove the file from the index even when the working directory still has such a file\&. (Implies \-\-remove\&.)
178 By default, when a file
181 \fIgit update\-index\fR
182 refuses an attempt to add
183 \fBpath/file\fR\&. Similarly if a file
187 cannot be added\&. With \-\-replace flag, existing entries that conflict with the entry being added are automatically removed with warning messages\&.
192 Instead of taking list of paths from the command line, read list of paths from the standard input\&. Paths are separated by LF (i\&.e\&. one path per line) by default\&.
197 Report what is being added and removed from index\&.
200 \-\-index\-version <n>
202 Write the resulting index out in the named on\-disk format version\&. Supported versions are 2, 3 and 4\&. The current default version is 2 or 3, depending on whether extra features are used, such as
205 Version 4 performs a simple pathname compression that reduces index size by 30%\-50% on large repositories, which results in faster load time\&. Version 4 is relatively young (first released in 1\&.8\&.0 in October 2012)\&. Other Git implementations such as JGit and libgit2 may not support it yet\&.
213 \fB\-\-index\-info\fR; paths are separated with NUL character instead of LF\&.
216 \-\-split\-index, \-\-no\-split\-index
218 Enable or disable split index mode\&. If split\-index mode is already enabled and
219 \fB\-\-split\-index\fR
220 is given again, all changes in $GIT_DIR/index are pushed back to the shared index file\&.
222 These options take effect whatever the value of the
223 \fBcore\&.splitIndex\fR
224 configuration variable (see
225 \fBgit-config\fR(1))\&. But a warning is emitted when the change goes against the configured value, as the configured value will take effect next time the index is read and this will remove the intended effect of the option\&.
228 \-\-untracked\-cache, \-\-no\-untracked\-cache
230 Enable or disable untracked cache feature\&. Please use
231 \fB\-\-test\-untracked\-cache\fR
232 before enabling it\&.
234 These options take effect whatever the value of the
235 \fBcore\&.untrackedCache\fR
236 configuration variable (see
237 \fBgit-config\fR(1))\&. But a warning is emitted when the change goes against the configured value, as the configured value will take effect next time the index is read and this will remove the intended effect of the option\&.
240 \-\-test\-untracked\-cache
242 Only perform tests on the working directory to make sure untracked cache can be used\&. You have to manually enable untracked cache using
243 \fB\-\-untracked\-cache\fR
245 \fB\-\-force\-untracked\-cache\fR
247 \fBcore\&.untrackedCache\fR
248 configuration variable afterwards if you really want to use it\&. If a test fails the exit code is 1 and a message explains what is not working as needed, otherwise the exit code is 0 and OK is printed\&.
251 \-\-force\-untracked\-cache
254 \fB\-\-untracked\-cache\fR\&. Provided for backwards compatibility with older versions of Git where
255 \fB\-\-untracked\-cache\fR
257 \fB\-\-test\-untracked\-cache\fR
258 but this option would enable the extension unconditionally\&.
261 \-\-fsmonitor, \-\-no\-fsmonitor
263 Enable or disable files system monitor feature\&. These options take effect whatever the value of the
264 \fBcore\&.fsmonitor\fR
265 configuration variable (see
266 \fBgit-config\fR(1))\&. But a warning is emitted when the change goes against the configured value, as the configured value will take effect next time the index is read and this will remove the intended effect of the option\&.
271 Do not interpret any more arguments as options\&.
276 Files to act on\&. Note that files beginning with
278 are discarded\&. This includes
281 \fBdir/\&./file\fR\&. If you don\(cqt want this, then use cleaner names\&. The same applies to directories ending
286 .SH "USING \-\-REFRESH"
288 \fB\-\-refresh\fR does not calculate a new sha1 file or bring the index up to date for mode/content changes\&. But what it \fBdoes\fR do is to "re\-match" the stat information of a file with the index, so that you can refresh the index for a file that hasn\(cqt been changed but where the stat entry is out of date\&.
290 For example, you\(cqd want to do this after doing a \fIgit read\-tree\fR, to link up the stat index details with the proper files\&.
291 .SH "USING \-\-CACHEINFO OR \-\-INFO\-ONLY"
293 \fB\-\-cacheinfo\fR is used to register a file that is not in the current working directory\&. This is useful for minimum\-checkout merging\&.
295 To pretend you have a file at path with mode and sha1, say:
301 $ git update\-index \-\-add \-\-cacheinfo <mode>,<sha1>,<path>
308 \fB\-\-info\-only\fR is used to register files without placing them in the object database\&. This is useful for status\-only repositories\&.
310 Both \fB\-\-cacheinfo\fR and \fB\-\-info\-only\fR behave similarly: the index is updated but the object database isn\(cqt\&. \fB\-\-cacheinfo\fR is useful when the object is in the database but the file isn\(cqt available locally\&. \fB\-\-info\-only\fR is useful when the file is available, but you do not wish to update the object database\&.
311 .SH "USING \-\-INDEX\-INFO"
313 \fB\-\-index\-info\fR is a more powerful mechanism that lets you feed multiple entry definitions from the standard input, and designed specifically for scripts\&. It can take inputs of three formats:
323 mode SP type SP sha1 TAB path
325 This format is to stuff
327 output into the index\&.
338 mode SP sha1 SP stage TAB path
340 This format is to put higher order stages into the index file and matches
341 \fIgit ls\-files \-\-stage\fR
353 mode SP sha1 TAB path
355 This format is no longer produced by any Git command, but is and will continue to be supported by
356 \fBupdate\-index \-\-index\-info\fR\&.
359 To place a higher stage entry to the index, the path should first be removed by feeding a mode=0 entry for the path, and then feeding necessary input lines in the third format\&.
361 For example, starting with this index:
368 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 0 frotz
375 you can feed the following input to \fB\-\-index\-info\fR:
381 $ git update\-index \-\-index\-info
382 0 0000000000000000000000000000000000000000 frotz
383 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz
384 100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz
391 The first line of the input feeds 0 as the mode to remove the path; the SHA\-1 does not matter as long as it is well formatted\&. Then the second and third line feeds stage 1 and stage 2 entries for that path\&. After the above, we would end up with this:
398 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz
399 100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz
405 .SH "USING \(lqASSUME UNCHANGED\(rq BIT"
407 Many operations in Git depend on your filesystem to have an efficient \fBlstat(2)\fR implementation, so that \fBst_mtime\fR information for working tree files can be cheaply checked to see if the file contents have changed from the version recorded in the index file\&. Unfortunately, some filesystems have inefficient \fBlstat(2)\fR\&. If your filesystem is one of them, you can set "assume unchanged" bit to paths you have not changed to cause Git not to do this check\&. Note that setting this bit on a path does not mean Git will check the contents of the file to see if it has changed \(em it makes Git to omit any checking and assume it has \fBnot\fR changed\&. When you make changes to working tree files, you have to explicitly tell Git about it by dropping "assume unchanged" bit, either before or after you modify them\&.
409 In order to set "assume unchanged" bit, use \fB\-\-assume\-unchanged\fR option\&. To unset, use \fB\-\-no\-assume\-unchanged\fR\&. To see which files have the "assume unchanged" bit set, use \fBgit ls\-files \-v\fR (see \fBgit-ls-files\fR(1))\&.
411 The command looks at \fBcore\&.ignorestat\fR configuration variable\&. When this is true, paths updated with \fBgit update\-index paths\&.\&.\&.\fR and paths updated with other Git commands that update both index and working tree (e\&.g\&. \fIgit apply \-\-index\fR, \fIgit checkout\-index \-u\fR, and \fIgit read\-tree \-u\fR) are automatically marked as "assume unchanged"\&. Note that "assume unchanged" bit is \fBnot\fR set if \fBgit update\-index \-\-refresh\fR finds the working tree file matches the index (use \fBgit update\-index \-\-really\-refresh\fR if you want to mark them as "assume unchanged")\&.
414 To update and refresh only the files already checked out:
420 $ git checkout\-index \-n \-f \-a && git update\-index \-\-ignore\-missing \-\-refresh
428 On an inefficient filesystem with \fBcore\&.ignorestat\fR set
435 $ git update\-index \-\-really\-refresh \fB(1)\fR
436 $ git update\-index \-\-no\-assume\-unchanged foo\&.c \fB(2)\fR
437 $ git diff \-\-name\-only \fB(3)\fR
439 $ git diff \-\-name\-only \fB(4)\fR
441 $ git update\-index foo\&.c \fB(5)\fR
442 $ git diff \-\-name\-only \fB(6)\fR
444 $ git diff \-\-name\-only \fB(7)\fR
445 $ git update\-index \-\-no\-assume\-unchanged foo\&.c \fB(8)\fR
446 $ git diff \-\-name\-only \fB(9)\fR
453 \fB1. \fRforces lstat(2) to set "assume unchanged" bits for paths that match index\&.
455 \fB2. \fRmark the path to be edited\&.
457 \fB3. \fRthis does lstat(2) and finds index matches the path\&.
459 \fB4. \fRthis does lstat(2) and finds index does
463 \fB5. \fRregistering the new version to index sets "assume unchanged" bit\&.
465 \fB6. \fRand it is assumed unchanged\&.
467 \fB7. \fReven after you edit it\&.
469 \fB8. \fRyou can tell about the change after the fact\&.
471 \fB9. \fRnow it checks with lstat(2) and finds it has been changed\&.
474 .SH "SKIP\-WORKTREE BIT"
476 Skip\-worktree bit can be defined in one (long) sentence: When reading an entry, if it is marked as skip\-worktree, then Git pretends its working directory version is up to date and read the index version instead\&.
478 To elaborate, "reading" means checking for file existence, reading file attributes or file content\&. The working directory version may be present or absent\&. If present, its content may match against the index version or not\&. Writing is not affected by this bit, content safety is still first priority\&. Note that Git \fIcan\fR update working directory file, that is marked skip\-worktree, if it is safe to do so (i\&.e\&. working directory version matches index version)
480 Although this bit looks similar to assume\-unchanged bit, its goal is different from assume\-unchanged bit\(cqs\&. Skip\-worktree also takes precedence over assume\-unchanged bit when both are set\&.
483 This mode is designed for repositories with very large indexes, and aims at reducing the time it takes to repeatedly write these indexes\&.
485 In this mode, the index is split into two files, $GIT_DIR/index and $GIT_DIR/sharedindex\&.<SHA\-1>\&. Changes are accumulated in $GIT_DIR/index, the split index, while the shared index file contains all index entries and stays unchanged\&.
487 All changes in the split index are pushed back to the shared index file when the number of entries in the split index reaches a level specified by the splitIndex\&.maxPercentChange config variable (see \fBgit-config\fR(1))\&.
489 Each time a new shared index file is created, the old shared index files are deleted if their modification time is older than what is specified by the splitIndex\&.sharedIndexExpire config variable (see \fBgit-config\fR(1))\&.
491 To avoid deleting a shared index file that is still used, its modification time is updated to the current time every time a new split index based on the shared index file is either created or read from\&.
492 .SH "UNTRACKED CACHE"
494 This cache is meant to speed up commands that involve determining untracked files such as \fBgit status\fR\&.
496 This feature works by recording the mtime of the working tree directories and then omitting reading directories and stat calls against files in those directories whose mtime hasn\(cqt changed\&. For this to work the underlying operating system and file system must change the \fBst_mtime\fR field of directories if files in the directory are added, modified or deleted\&.
498 You can test whether the filesystem supports that with the \fB\-\-test\-untracked\-cache\fR option\&. The \fB\-\-untracked\-cache\fR option used to implicitly perform that test in older versions of Git, but that\(cqs no longer the case\&.
500 If you want to enable (or disable) this feature, it is easier to use the \fBcore\&.untrackedCache\fR configuration variable (see \fBgit-config\fR(1)) than using the \fB\-\-untracked\-cache\fR option to \fBgit update\-index\fR in each repository, especially if you want to do so across all repositories you use, because you can set the configuration variable to \fBtrue\fR (or \fBfalse\fR) in your \fB$HOME/\&.gitconfig\fR just once and have it affect all repositories you touch\&.
502 When the \fBcore\&.untrackedCache\fR configuration variable is changed, the untracked cache is added to or removed from the index the next time a command reads the index; while when \fB\-\-[no\-|force\-]untracked\-cache\fR are used, the untracked cache is immediately added to or removed from the index\&.
504 Before 2\&.17, the untracked cache had a bug where replacing a directory with a symlink to another directory could cause it to incorrectly show files tracked by git as untracked\&. See the "status: add a failing test showing a core\&.untrackedCache bug" commit to git\&.git\&. A workaround for that is (and this might work for other undiscovered bugs in the future):
510 $ git \-c core\&.untrackedCache=false status
517 This bug has also been shown to affect non\-symlink cases of replacing a directory with a file when it comes to the internal structures of the untracked cache, but no case has been reported where this resulted in wrong "git status" output\&.
519 There are also cases where existing indexes written by git versions before 2\&.17 will reference directories that don\(cqt exist anymore, potentially causing many "could not open directory" warnings to be printed on "git status"\&. These are new warnings for existing issues that were previously silently discarded\&.
521 As with the bug described above the solution is to one\-off do a "git status" run with \fBcore\&.untrackedCache=false\fR to flush out the leftover bad data\&.
522 .SH "FILE SYSTEM MONITOR"
524 This feature is intended to speed up git operations for repos that have large working directories\&.
526 It enables git to work together with a file system monitor (see the "fsmonitor\-watchman" section of \fBgithooks\fR(5)) that can inform it as to what files have been modified\&. This enables git to avoid having to lstat() every file to find modified files\&.
528 When used in conjunction with the untracked cache, it can further improve performance by avoiding the cost of scanning the entire working directory looking for new files\&.
530 If you want to enable (or disable) this feature, it is easier to use the \fBcore\&.fsmonitor\fR configuration variable (see \fBgit-config\fR(1)) than using the \fB\-\-fsmonitor\fR option to \fBgit update\-index\fR in each repository, especially if you want to do so across all repositories you use, because you can set the configuration variable in your \fB$HOME/\&.gitconfig\fR just once and have it affect all repositories you touch\&.
532 When the \fBcore\&.fsmonitor\fR configuration variable is changed, the file system monitor is added to or removed from the index the next time a command reads the index\&. When \fB\-\-[no\-]fsmonitor\fR are used, the file system monitor is immediately added to or removed from the index\&.
535 The command honors \fBcore\&.filemode\fR configuration variable\&. If your repository is on a filesystem whose executable bits are unreliable, this should be set to \fIfalse\fR (see \fBgit-config\fR(1))\&. This causes the command to ignore differences in file modes recorded in the index and the file mode on the filesystem if they differ only on executable bit\&. On such an unfortunate filesystem, you may need to use \fIgit update\-index \-\-chmod=\fR\&.
537 Quite similarly, if \fBcore\&.symlinks\fR configuration variable is set to \fIfalse\fR (see \fBgit-config\fR(1)), symbolic links are checked out as plain files, and this command does not modify a recorded file mode from symbolic link to regular file\&.
539 The command looks at \fBcore\&.ignorestat\fR configuration variable\&. See \fIUsing "assume unchanged" bit\fR section above\&.
541 The command also looks at \fBcore\&.trustctime\fR configuration variable\&. It can be useful when the inode change time is regularly modified by something outside Git (file system crawlers and backup systems use ctime for marking files processed) (see \fBgit-config\fR(1))\&.
543 The untracked cache extension can be enabled by the \fBcore\&.untrackedCache\fR configuration variable (see \fBgit-config\fR(1))\&.
546 Users often try to use the assume\-unchanged and skip\-worktree bits to tell Git to ignore changes to files that are tracked\&. This does not work as expected, since Git may still check working tree files against the index when performing certain operations\&. In general, Git does not provide a way to ignore changes to tracked files, so alternate solutions are recommended\&.
548 For example, if the file you want to change is some sort of config file, the repository can include a sample config file that can then be copied into the ignored name and modified\&. The repository can even include a script to treat the sample file as a template, modifying and copying it automatically\&.
551 \fBgit-config\fR(1), \fBgit-add\fR(1), \fBgit-ls-files\fR(1)
554 Part of the \fBgit\fR(1) suite