1git-update-index(1) 2=================== 3 4NAME 5---- 6git-update-index - Register file contents in the working tree to the index 7 8 9SYNOPSIS 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 [--ignore-submodules] 20 [--[no-|force-]untracked-cache] 21 [--really-refresh] [--unresolve] [--again | -g] 22 [--info-only] [--index-info] 23 [-z] [--stdin] [--index-version <n>] 24 [--verbose] 25 [--] [<file>...] 26 27DESCRIPTION 28----------- 29Modifies the index or directory cache. Each file mentioned is updated 30into the index and any 'unmerged' or 'needs updating' state is 31cleared. 32 33See also linkgit:git-add[1] for a more user-friendly way to do some of 34the most common operations on the index. 35 36The way 'git update-index' handles files it is told about can be modified 37using the various options: 38 39OPTIONS 40------- 41--add:: 42 If a specified file isn't in the index already then it's 43 added. 44 Default behaviour is to ignore new files. 45 46--remove:: 47 If a specified file is in the index but is missing then it's 48 removed. 49 Default behavior is to ignore removed file. 50 51--refresh:: 52 Looks at the current index and checks to see if merges or 53 updates are needed by checking stat() information. 54 55-q:: 56 Quiet. If --refresh finds that the index needs an update, the 57 default behavior is to error out. This option makes 58 'git update-index' continue anyway. 59 60--ignore-submodules:: 61 Do not try to update submodules. This option is only respected 62 when passed before --refresh. 63 64--unmerged:: 65 If --refresh finds unmerged changes in the index, the default 66 behavior is to error out. This option makes 'git update-index' 67 continue anyway. 68 69--ignore-missing:: 70 Ignores missing files during a --refresh 71 72--cacheinfo <mode>,<object>,<path>:: 73--cacheinfo <mode> <object> <path>:: 74 Directly insert the specified info into the index. For 75 backward compatibility, you can also give these three 76 arguments as three separate parameters, but new users are 77 encouraged to use a single-parameter form. 78 79--index-info:: 80 Read index information from stdin. 81 82--chmod=(+|-)x:: 83 Set the execute permissions on the updated files. 84 85--[no-]assume-unchanged:: 86 When this flag is specified, the object names recorded 87 for the paths are not updated. Instead, this option 88 sets/unsets the "assume unchanged" bit for the 89 paths. When the "assume unchanged" bit is on, the user 90 promises not to change the file and allows Git to assume 91 that the working tree file matches what is recorded in 92 the index. If you want to change the working tree file, 93 you need to unset the bit to tell Git. This is 94 sometimes helpful when working with a big project on a 95 filesystem that has very slow lstat(2) system call 96 (e.g. cifs). 97+ 98Git will fail (gracefully) in case it needs to modify this file 99in the index e.g. when merging in a commit; 100thus, in case the assumed-untracked file is changed upstream, 101you will need to handle the situation manually. 102 103--really-refresh:: 104 Like '--refresh', but checks stat information unconditionally, 105 without regard to the "assume unchanged" setting. 106 107--[no-]skip-worktree:: 108 When one of these flags is specified, the object name recorded 109 for the paths are not updated. Instead, these options 110 set and unset the "skip-worktree" bit for the paths. See 111 section "Skip-worktree bit" below for more information. 112 113-g:: 114--again:: 115 Runs 'git update-index' itself on the paths whose index 116 entries are different from those from the `HEAD` commit. 117 118--unresolve:: 119 Restores the 'unmerged' or 'needs updating' state of a 120 file during a merge if it was cleared by accident. 121 122--info-only:: 123 Do not create objects in the object database for all 124 <file> arguments that follow this flag; just insert 125 their object IDs into the index. 126 127--force-remove:: 128 Remove the file from the index even when the working directory 129 still has such a file. (Implies --remove.) 130 131--replace:: 132 By default, when a file `path` exists in the index, 133 'git update-index' refuses an attempt to add `path/file`. 134 Similarly if a file `path/file` exists, a file `path` 135 cannot be added. With --replace flag, existing entries 136 that conflict with the entry being added are 137 automatically removed with warning messages. 138 139--stdin:: 140 Instead of taking list of paths from the command line, 141 read list of paths from the standard input. Paths are 142 separated by LF (i.e. one path per line) by default. 143 144--verbose:: 145 Report what is being added and removed from index. 146 147--index-version <n>:: 148 Write the resulting index out in the named on-disk format version. 149 Supported versions are 2, 3 and 4. The current default version is 2 150 or 3, depending on whether extra features are used, such as 151 `git add -N`. 152+ 153Version 4 performs a simple pathname compression that reduces index 154size by 30%-50% on large repositories, which results in faster load 155time. Version 4 is relatively young (first released in in 1.8.0 in 156October 2012). Other Git implementations such as JGit and libgit2 157may not support it yet. 158 159-z:: 160 Only meaningful with `--stdin` or `--index-info`; paths are 161 separated with NUL character instead of LF. 162 163--split-index:: 164--no-split-index:: 165 Enable or disable split index mode. If enabled, the index is 166 split into two files, $GIT_DIR/index and $GIT_DIR/sharedindex.<SHA-1>. 167 Changes are accumulated in $GIT_DIR/index while the shared 168 index file contains all index entries stays unchanged. If 169 split-index mode is already enabled and `--split-index` is 170 given again, all changes in $GIT_DIR/index are pushed back to 171 the shared index file. This mode is designed for very large 172 indexes that take a significant amount of time to read or write. 173 174--untracked-cache:: 175--no-untracked-cache:: 176 Enable or disable untracked cache extension. This could speed 177 up for commands that involve determining untracked files such 178 as `git status`. The underlying operating system and file 179 system must change `st_mtime` field of a directory if files 180 are added or deleted in that directory. 181 182--force-untracked-cache:: 183 For safety, `--untracked-cache` performs tests on the working 184 directory to make sure untracked cache can be used. These 185 tests can take a few seconds. `--force-untracked-cache` can be 186 used to skip the tests. 187 188\--:: 189 Do not interpret any more arguments as options. 190 191<file>:: 192 Files to act on. 193 Note that files beginning with '.' are discarded. This includes 194 `./file` and `dir/./file`. If you don't want this, then use 195 cleaner names. 196 The same applies to directories ending '/' and paths with '//' 197 198Using --refresh 199--------------- 200'--refresh' does not calculate a new sha1 file or bring the index 201up-to-date for mode/content changes. But what it *does* do is to 202"re-match" the stat information of a file with the index, so that you 203can refresh the index for a file that hasn't been changed but where 204the stat entry is out of date. 205 206For example, you'd want to do this after doing a 'git read-tree', to link 207up the stat index details with the proper files. 208 209Using --cacheinfo or --info-only 210-------------------------------- 211'--cacheinfo' is used to register a file that is not in the 212current working directory. This is useful for minimum-checkout 213merging. 214 215To pretend you have a file with mode and sha1 at path, say: 216 217---------------- 218$ git update-index --cacheinfo <mode>,<sha1>,<path> 219---------------- 220 221'--info-only' is used to register files without placing them in the object 222database. This is useful for status-only repositories. 223 224Both '--cacheinfo' and '--info-only' behave similarly: the index is updated 225but the object database isn't. '--cacheinfo' is useful when the object is 226in the database but the file isn't available locally. '--info-only' is 227useful when the file is available, but you do not wish to update the 228object database. 229 230 231Using --index-info 232------------------ 233 234`--index-info` is a more powerful mechanism that lets you feed 235multiple entry definitions from the standard input, and designed 236specifically for scripts. It can take inputs of three formats: 237 238 . mode SP sha1 TAB path 239+ 240The first format is what "git-apply --index-info" 241reports, and used to reconstruct a partial tree 242that is used for phony merge base tree when falling 243back on 3-way merge. 244 245 . mode SP type SP sha1 TAB path 246+ 247The second format is to stuff 'git ls-tree' output 248into the index file. 249 250 . mode SP sha1 SP stage TAB path 251+ 252This format is to put higher order stages into the 253index file and matches 'git ls-files --stage' output. 254 255To place a higher stage entry to the index, the path should 256first be removed by feeding a mode=0 entry for the path, and 257then feeding necessary input lines in the third format. 258 259For example, starting with this index: 260 261------------ 262$ git ls-files -s 263100644 8a1218a1024a212bb3db30becd860315f9f3ac52 0 frotz 264------------ 265 266you can feed the following input to `--index-info`: 267 268------------ 269$ git update-index --index-info 2700 0000000000000000000000000000000000000000 frotz 271100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz 272100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz 273------------ 274 275The first line of the input feeds 0 as the mode to remove the 276path; the SHA-1 does not matter as long as it is well formatted. 277Then the second and third line feeds stage 1 and stage 2 entries 278for that path. After the above, we would end up with this: 279 280------------ 281$ git ls-files -s 282100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz 283100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz 284------------ 285 286 287Using ``assume unchanged'' bit 288------------------------------ 289 290Many operations in Git depend on your filesystem to have an 291efficient `lstat(2)` implementation, so that `st_mtime` 292information for working tree files can be cheaply checked to see 293if the file contents have changed from the version recorded in 294the index file. Unfortunately, some filesystems have 295inefficient `lstat(2)`. If your filesystem is one of them, you 296can set "assume unchanged" bit to paths you have not changed to 297cause Git not to do this check. Note that setting this bit on a 298path does not mean Git will check the contents of the file to 299see if it has changed -- it makes Git to omit any checking and 300assume it has *not* changed. When you make changes to working 301tree files, you have to explicitly tell Git about it by dropping 302"assume unchanged" bit, either before or after you modify them. 303 304In order to set "assume unchanged" bit, use `--assume-unchanged` 305option. To unset, use `--no-assume-unchanged`. To see which files 306have the "assume unchanged" bit set, use `git ls-files -v` 307(see linkgit:git-ls-files[1]). 308 309The command looks at `core.ignorestat` configuration variable. When 310this is true, paths updated with `git update-index paths...` and 311paths updated with other Git commands that update both index and 312working tree (e.g. 'git apply --index', 'git checkout-index -u', 313and 'git read-tree -u') are automatically marked as "assume 314unchanged". Note that "assume unchanged" bit is *not* set if 315`git update-index --refresh` finds the working tree file matches 316the index (use `git update-index --really-refresh` if you want 317to mark them as "assume unchanged"). 318 319 320Examples 321-------- 322To update and refresh only the files already checked out: 323 324---------------- 325$ git checkout-index -n -f -a && git update-index --ignore-missing --refresh 326---------------- 327 328On an inefficient filesystem with `core.ignorestat` set:: 329+ 330------------ 331$ git update-index --really-refresh <1> 332$ git update-index --no-assume-unchanged foo.c <2> 333$ git diff --name-only <3> 334$ edit foo.c 335$ git diff --name-only <4> 336M foo.c 337$ git update-index foo.c <5> 338$ git diff --name-only <6> 339$ edit foo.c 340$ git diff --name-only <7> 341$ git update-index --no-assume-unchanged foo.c <8> 342$ git diff --name-only <9> 343M foo.c 344------------ 345+ 346<1> forces lstat(2) to set "assume unchanged" bits for paths that match index. 347<2> mark the path to be edited. 348<3> this does lstat(2) and finds index matches the path. 349<4> this does lstat(2) and finds index does *not* match the path. 350<5> registering the new version to index sets "assume unchanged" bit. 351<6> and it is assumed unchanged. 352<7> even after you edit it. 353<8> you can tell about the change after the fact. 354<9> now it checks with lstat(2) and finds it has been changed. 355 356 357Skip-worktree bit 358----------------- 359 360Skip-worktree bit can be defined in one (long) sentence: When reading 361an entry, if it is marked as skip-worktree, then Git pretends its 362working directory version is up to date and read the index version 363instead. 364 365To elaborate, "reading" means checking for file existence, reading 366file attributes or file content. The working directory version may be 367present or absent. If present, its content may match against the index 368version or not. Writing is not affected by this bit, content safety 369is still first priority. Note that Git _can_ update working directory 370file, that is marked skip-worktree, if it is safe to do so (i.e. 371working directory version matches index version) 372 373Although this bit looks similar to assume-unchanged bit, its goal is 374different from assume-unchanged bit's. Skip-worktree also takes 375precedence over assume-unchanged bit when both are set. 376 377 378Configuration 379------------- 380 381The command honors `core.filemode` configuration variable. If 382your repository is on a filesystem whose executable bits are 383unreliable, this should be set to 'false' (see linkgit:git-config[1]). 384This causes the command to ignore differences in file modes recorded 385in the index and the file mode on the filesystem if they differ only on 386executable bit. On such an unfortunate filesystem, you may 387need to use 'git update-index --chmod='. 388 389Quite similarly, if `core.symlinks` configuration variable is set 390to 'false' (see linkgit:git-config[1]), symbolic links are checked out 391as plain files, and this command does not modify a recorded file mode 392from symbolic link to regular file. 393 394The command looks at `core.ignorestat` configuration variable. See 395'Using "assume unchanged" bit' section above. 396 397The command also looks at `core.trustctime` configuration variable. 398It can be useful when the inode change time is regularly modified by 399something outside Git (file system crawlers and backup systems use 400ctime for marking files processed) (see linkgit:git-config[1]). 401 402 403SEE ALSO 404-------- 405linkgit:git-config[1], 406linkgit:git-add[1], 407linkgit:git-ls-files[1] 408 409GIT 410--- 411Part of the linkgit:git[1] suite