2 .\" Title: git-update-index
3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets v1.79.2 <http://docbook.sf.net/>
7 .\" Source: Git 2.46.0.288.g3a7362eb9f
10 .TH "GIT\-UPDATE\-INDEX" "1" "2024-08-21" "Git 2\&.46\&.0\&.288\&.g3a7362" "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>]
51 [\-\-show\-index\-version]
53 [\-\-] [<file>\&...\:]
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 files\&.
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 a 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 names 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 names 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 of 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 a list of paths from the command line, read a 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 the 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
203 \fBgit add \-N\fR\&. With
204 \fB\-\-verbose\fR, also report the version the index file uses before and after this command\&.
206 Version 4 performs a simple pathname compression that reduces index size by 30%\-50% on large repositories, which results in faster load time\&. Git supports it since version 1\&.8\&.0, released in October 2012, and support for it was added to libgit2 in 2016 and to JGit in 2020\&. Older versions of this manual page called it "relatively young", but it should be considered mature technology these days\&.
209 \-\-show\-index\-version
211 Report the index format version used by the on\-disk index file\&. See
212 \fB\-\-index\-version\fR
221 \fB\-\-index\-info\fR; paths are separated with NUL character instead of LF\&.
224 \-\-split\-index, \-\-no\-split\-index
226 Enable or disable split index mode\&. If split\-index mode is already enabled and
227 \fB\-\-split\-index\fR
228 is given again, all changes in $GIT_DIR/index are pushed back to the shared index file\&.
230 These options take effect whatever the value of the
231 \fBcore\&.splitIndex\fR
232 configuration variable (see
233 \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\&.
236 \-\-untracked\-cache, \-\-no\-untracked\-cache
238 Enable or disable untracked cache feature\&. Please use
239 \fB\-\-test\-untracked\-cache\fR
240 before enabling it\&.
242 These options take effect whatever the value of the
243 \fBcore\&.untrackedCache\fR
244 configuration variable (see
245 \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\&.
248 \-\-test\-untracked\-cache
250 Only perform tests on the working directory to make sure untracked cache can be used\&. You have to manually enable untracked cache using
251 \fB\-\-untracked\-cache\fR
253 \fB\-\-force\-untracked\-cache\fR
255 \fBcore\&.untrackedCache\fR
256 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\&.
259 \-\-force\-untracked\-cache
262 \fB\-\-untracked\-cache\fR\&. Provided for backwards compatibility with older versions of Git where
263 \fB\-\-untracked\-cache\fR
265 \fB\-\-test\-untracked\-cache\fR
266 but this option would enable the extension unconditionally\&.
269 \-\-fsmonitor, \-\-no\-fsmonitor
271 Enable or disable files system monitor feature\&. These options take effect whatever the value of the
272 \fBcore\&.fsmonitor\fR
273 configuration variable (see
274 \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\&.
279 Do not interpret any more arguments as options\&.
284 Files to act on\&. Note that files beginning with
286 are discarded\&. This includes
289 \fBdir/\&./file\fR\&. If you don\(cqt want this, then use cleaner names\&. The same applies to directories ending
294 .SH "USING \-\-REFRESH"
296 \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\&.
298 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\&.
299 .SH "USING \-\-CACHEINFO OR \-\-INFO\-ONLY"
301 \fB\-\-cacheinfo\fR is used to register a file that is not in the current working directory\&. This is useful for minimum\-checkout merging\&.
303 To pretend you have a file at path with mode and sha1, say:
309 $ git update\-index \-\-add \-\-cacheinfo <mode>,<sha1>,<path>
315 \fB\-\-info\-only\fR is used to register files without placing them in the object database\&. This is useful for status\-only repositories\&.
317 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\&.
318 .SH "USING \-\-INDEX\-INFO"
320 \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:
330 mode SP type SP sha1 TAB path
332 This format is to stuff
334 output into the index\&.
345 mode SP sha1 SP stage TAB path
347 This format is to put higher order stages into the index file and matches
348 \fIgit ls\-files \-\-stage\fR
360 mode SP sha1 TAB path
362 This format is no longer produced by any Git command, but is and will continue to be supported by
363 \fBupdate\-index \-\-index\-info\fR\&.
366 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\&.
368 For example, starting with this index:
375 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 0 frotz
381 you can feed the following input to \fB\-\-index\-info\fR:
387 $ git update\-index \-\-index\-info
388 0 0000000000000000000000000000000000000000 frotz
389 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz
390 100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz
396 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:
403 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz
404 100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz
409 .SH "USING \(lqASSUME UNCHANGED\(rq BIT"
411 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\&.
413 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))\&.
415 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")\&.
417 Sometimes users confuse the assume\-unchanged bit with the skip\-worktree bit\&. See the final paragraph in the "Skip\-worktree bit" section below for an explanation of the differences\&.
420 To update and refresh only the files already checked out:
426 $ git checkout\-index \-n \-f \-a && git update\-index \-\-ignore\-missing \-\-refresh
432 On an inefficient filesystem with \fBcore\&.ignorestat\fR set
439 $ git update\-index \-\-really\-refresh \fB(1)\fR
440 $ git update\-index \-\-no\-assume\-unchanged foo\&.c \fB(2)\fR
441 $ git diff \-\-name\-only \fB(3)\fR
443 $ git diff \-\-name\-only \fB(4)\fR
445 $ git update\-index foo\&.c \fB(5)\fR
446 $ git diff \-\-name\-only \fB(6)\fR
448 $ git diff \-\-name\-only \fB(7)\fR
449 $ git update\-index \-\-no\-assume\-unchanged foo\&.c \fB(8)\fR
450 $ git diff \-\-name\-only \fB(9)\fR
458 r lw(\n(.lu*75u/100u).
460 forces lstat(2) to set "assume unchanged" bits for paths that match index\&.
463 mark the path to be edited\&.
466 this does lstat(2) and finds index matches the path\&.
469 this does lstat(2) and finds index does
474 registering the new version to index sets "assume unchanged" bit\&.
477 and it is assumed unchanged\&.
480 even after you edit it\&.
483 you can tell about the change after the fact\&.
486 now it checks with lstat(2) and finds it has been changed\&.
490 .SH "SKIP\-WORKTREE BIT"
492 Skip\-worktree bit can be defined in one (long) sentence: Tell git to avoid writing the file to the working directory when reasonably possible, and treat the file as unchanged when it is not present in the working directory\&.
494 Note that not all git commands will pay attention to this bit, and some only partially support it\&.
496 The update\-index flags and the read\-tree capabilities relating to the skip\-worktree bit predated the introduction of the \fBgit-sparse-checkout\fR(1) command, which provides a much easier way to configure and handle the skip\-worktree bits\&. If you want to reduce your working tree to only deal with a subset of the files in the repository, we strongly encourage the use of \fBgit-sparse-checkout\fR(1) in preference to the low\-level update\-index and read\-tree primitives\&.
498 The primary purpose of the skip\-worktree bit is to enable sparse checkouts, i\&.e\&. to have working directories with only a subset of paths present\&. When the skip\-worktree bit is set, Git commands (such as \fBswitch\fR, \fBpull\fR, \fBmerge\fR) will avoid writing these files\&. However, these commands will sometimes write these files anyway in important cases such as conflicts during a merge or rebase\&. Git commands will also avoid treating the lack of such files as an intentional deletion; for example \fBgit add \-u\fR will not stage a deletion for these files and \fBgit commit \-a\fR will not make a commit deleting them either\&.
500 Although this bit looks similar to assume\-unchanged bit, its goal is different\&. The assume\-unchanged bit is for leaving the file in the working tree but having Git omit checking it for changes and presuming that the file has not been changed (though if it can determine without stat\(cqing the file that it has changed, it is free to record the changes)\&. skip\-worktree tells Git to ignore the absence of the file, avoid updating it when possible with commands that normally update much of the working directory (e\&.g\&. \fBcheckout\fR, \fBswitch\fR, \fBpull\fR, etc\&.), and not have its absence be recorded in commits\&. Note that in sparse checkouts (setup by \fBgit sparse\-checkout\fR or by configuring core\&.sparseCheckout to true), if a file is marked as skip\-worktree in the index but is found in the working tree, Git will clear the skip\-worktree bit for that file\&.
503 This mode is designed for repositories with very large indexes, and aims at reducing the time it takes to repeatedly write these indexes\&.
505 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\&.
507 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))\&.
509 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))\&.
511 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\&.
512 .SH "UNTRACKED CACHE"
514 This cache is meant to speed up commands that involve determining untracked files such as \fBgit status\fR\&.
516 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\&.
518 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\&.
520 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\&.
522 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\&.
524 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):
530 $ git \-c core\&.untrackedCache=false status
536 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\&.
538 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\&.
540 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\&.
541 .SH "FILE SYSTEM MONITOR"
543 This feature is intended to speed up git operations for repos that have large working directories\&.
545 It enables git to work together with a file system monitor (see \fBgit-fsmonitor--daemon\fR(1) and 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\&.
547 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\&.
549 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\&.
551 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\&.
554 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\&.
556 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\&.
558 The command looks at \fBcore\&.ignorestat\fR configuration variable\&. See \fIUsing "assume unchanged" bit\fR section above\&.
560 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))\&.
562 The untracked cache extension can be enabled by the \fBcore\&.untrackedCache\fR configuration variable (see \fBgit-config\fR(1))\&.
565 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\&.
567 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\&.
570 \fBgit-config\fR(1), \fBgit-add\fR(1), \fBgit-ls-files\fR(1)
573 Part of the \fBgit\fR(1) suite