1GIT-UPDATE-INDEX(1)               Git Manual               GIT-UPDATE-INDEX(1)
2
3
4

NAME

6       git-update-index - Register file contents in the working tree to the
7       index
8

SYNOPSIS

10       git update-index
11                    [--add] [--remove | --force-remove] [--replace]
12                    [--refresh] [-q] [--unmerged] [--ignore-missing]
13                    [(--cacheinfo <mode> <object> <file>)...]
14                    [--chmod=(+|-)x]
15                    [--[no-]assume-unchanged]
16                    [--[no-]skip-worktree]
17                    [--ignore-submodules]
18                    [--really-refresh] [--unresolve] [--again | -g]
19                    [--info-only] [--index-info]
20                    [-z] [--stdin] [--index-version <n>]
21                    [--verbose]
22                    [--] [<file>...]
23
24

DESCRIPTION

26       Modifies the index or directory cache. Each file mentioned is updated
27       into the index and any unmerged or needs updating state is cleared.
28
29       See also git-add(1) for a more user-friendly way to do some of the most
30       common operations on the index.
31
32       The way git update-index handles files it is told about can be modified
33       using the various options:
34

OPTIONS

36       --add
37           If a specified file isn’t in the index already then it’s added.
38           Default behaviour is to ignore new files.
39
40       --remove
41           If a specified file is in the index but is missing then it’s
42           removed. Default behavior is to ignore removed file.
43
44       --refresh
45           Looks at the current index and checks to see if merges or updates
46           are needed by checking stat() information.
47
48       -q
49           Quiet. If --refresh finds that the index needs an update, the
50           default behavior is to error out. This option makes git
51           update-index continue anyway.
52
53       --ignore-submodules
54           Do not try to update submodules. This option is only respected when
55           passed before --refresh.
56
57       --unmerged
58           If --refresh finds unmerged changes in the index, the default
59           behavior is to error out. This option makes git update-index
60           continue anyway.
61
62       --ignore-missing
63           Ignores missing files during a --refresh
64
65       --cacheinfo <mode> <object> <path>
66           Directly insert the specified info into the index.
67
68       --index-info
69           Read index information from stdin.
70
71       --chmod=(+|-)x
72           Set the execute permissions on the updated files.
73
74       --[no-]assume-unchanged
75           When these flags are specified, the object names recorded for the
76           paths are not updated. Instead, these options set and unset the
77           "assume unchanged" bit for the paths. When the "assume unchanged"
78           bit is on, Git stops checking the working tree files for possible
79           modifications, so you need to manually unset the bit to tell Git
80           when you change the working tree file. This is sometimes helpful
81           when working with a big project on a filesystem that has very slow
82           lstat(2) system call (e.g. cifs).
83
84           This option can be also used as a coarse file-level mechanism to
85           ignore uncommitted changes in tracked files (akin to what
86           .gitignore does for untracked files). Git will fail (gracefully) in
87           case it needs to modify this file in the index e.g. when merging in
88           a commit; thus, in case the assumed-untracked file is changed
89           upstream, you will need to handle the situation manually.
90
91       --really-refresh
92           Like --refresh, but checks stat information unconditionally,
93           without regard to the "assume unchanged" setting.
94
95       --[no-]skip-worktree
96           When one of these flags is specified, the object name recorded for
97           the paths are not updated. Instead, these options set and unset the
98           "skip-worktree" bit for the paths. See section "Skip-worktree bit"
99           below for more information.
100
101       -g, --again
102           Runs git update-index itself on the paths whose index entries are
103           different from those from the HEAD commit.
104
105       --unresolve
106           Restores the unmerged or needs updating state of a file during a
107           merge if it was cleared by accident.
108
109       --info-only
110           Do not create objects in the object database for all <file>
111           arguments that follow this flag; just insert their object IDs into
112           the index.
113
114       --force-remove
115           Remove the file from the index even when the working directory
116           still has such a file. (Implies --remove.)
117
118       --replace
119           By default, when a file path exists in the index, git update-index
120           refuses an attempt to add path/file. Similarly if a file path/file
121           exists, a file path cannot be added. With --replace flag, existing
122           entries that conflict with the entry being added are automatically
123           removed with warning messages.
124
125       --stdin
126           Instead of taking list of paths from the command line, read list of
127           paths from the standard input. Paths are separated by LF (i.e. one
128           path per line) by default.
129
130       --verbose
131           Report what is being added and removed from index.
132
133       --index-version <n>
134           Write the resulting index out in the named on-disk format version.
135           Supported versions are 2, 3 and 4. The current default version is 2
136           or 3, depending on whether extra features are used, such as git add
137           -N.
138
139           Version 4 performs a simple pathname compression that reduces index
140           size by 30%-50% on large repositories, which results in faster load
141           time. Version 4 is relatively young (first released in in 1.8.0 in
142           October 2012). Other Git implementations such as JGit and libgit2
143           may not support it yet.
144
145       -z
146           Only meaningful with --stdin or --index-info; paths are separated
147           with NUL character instead of LF.
148
149       --
150           Do not interpret any more arguments as options.
151
152       <file>
153           Files to act on. Note that files beginning with .  are discarded.
154           This includes ./file and dir/./file. If you don’t want this, then
155           use cleaner names. The same applies to directories ending / and
156           paths with //
157

USING --REFRESH

159       --refresh does not calculate a new sha1 file or bring the index
160       up-to-date for mode/content changes. But what it does do is to
161       "re-match" the stat information of a file with the index, so that you
162       can refresh the index for a file that hasn’t been changed but where the
163       stat entry is out of date.
164
165       For example, you’d want to do this after doing a git read-tree, to link
166       up the stat index details with the proper files.
167

USING --CACHEINFO OR --INFO-ONLY

169       --cacheinfo is used to register a file that is not in the current
170       working directory. This is useful for minimum-checkout merging.
171
172       To pretend you have a file with mode and sha1 at path, say:
173
174           $ git update-index --cacheinfo mode sha1 path
175
176
177       --info-only is used to register files without placing them in the
178       object database. This is useful for status-only repositories.
179
180       Both --cacheinfo and --info-only behave similarly: the index is updated
181       but the object database isn’t. --cacheinfo is useful when the object is
182       in the database but the file isn’t available locally. --info-only is
183       useful when the file is available, but you do not wish to update the
184       object database.
185

USING --INDEX-INFO

187       --index-info is a more powerful mechanism that lets you feed multiple
188       entry definitions from the standard input, and designed specifically
189       for scripts. It can take inputs of three formats:
190
191        1. mode SP sha1 TAB path
192
193           The first format is what "git-apply --index-info" reports, and used
194           to reconstruct a partial tree that is used for phony merge base
195           tree when falling back on 3-way merge.
196
197        2. mode SP type SP sha1 TAB path
198
199           The second format is to stuff git ls-tree output into the index
200           file.
201
202        3. mode SP sha1 SP stage TAB path
203
204           This format is to put higher order stages into the index file and
205           matches git ls-files --stage output.
206
207       To place a higher stage entry to the index, the path should first be
208       removed by feeding a mode=0 entry for the path, and then feeding
209       necessary input lines in the third format.
210
211       For example, starting with this index:
212
213           $ git ls-files -s
214           100644 8a1218a1024a212bb3db30becd860315f9f3ac52 0       frotz
215
216
217       you can feed the following input to --index-info:
218
219           $ git update-index --index-info
220           0 0000000000000000000000000000000000000000      frotz
221           100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1       frotz
222           100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2       frotz
223
224
225       The first line of the input feeds 0 as the mode to remove the path; the
226       SHA-1 does not matter as long as it is well formatted. Then the second
227       and third line feeds stage 1 and stage 2 entries for that path. After
228       the above, we would end up with this:
229
230           $ git ls-files -s
231           100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1       frotz
232           100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2       frotz
233
234

USING “ASSUME UNCHANGED” BIT

236       Many operations in Git depend on your filesystem to have an efficient
237       lstat(2) implementation, so that st_mtime information for working tree
238       files can be cheaply checked to see if the file contents have changed
239       from the version recorded in the index file. Unfortunately, some
240       filesystems have inefficient lstat(2). If your filesystem is one of
241       them, you can set "assume unchanged" bit to paths you have not changed
242       to cause Git not to do this check. Note that setting this bit on a path
243       does not mean Git will check the contents of the file to see if it has
244       changed — it makes Git to omit any checking and assume it has not
245       changed. When you make changes to working tree files, you have to
246       explicitly tell Git about it by dropping "assume unchanged" bit, either
247       before or after you modify them.
248
249       In order to set "assume unchanged" bit, use --assume-unchanged option.
250       To unset, use --no-assume-unchanged. To see which files have the
251       "assume unchanged" bit set, use git ls-files -v (see git-ls-files(1)).
252
253       The command looks at core.ignorestat configuration variable. When this
254       is true, paths updated with git update-index paths... and paths updated
255       with other Git commands that update both index and working tree (e.g.
256       git apply --index, git checkout-index -u, and git read-tree -u) are
257       automatically marked as "assume unchanged". Note that "assume
258       unchanged" bit is not set if git update-index --refresh finds the
259       working tree file matches the index (use git update-index
260       --really-refresh if you want to mark them as "assume unchanged").
261

EXAMPLES

263       To update and refresh only the files already checked out:
264
265           $ git checkout-index -n -f -a && git update-index --ignore-missing --refresh
266
267
268
269       On an inefficient filesystem with core.ignorestat set
270
271               $ git update-index --really-refresh              (1)
272               $ git update-index --no-assume-unchanged foo.c   (2)
273               $ git diff --name-only                           (3)
274               $ edit foo.c
275               $ git diff --name-only                           (4)
276               M foo.c
277               $ git update-index foo.c                         (5)
278               $ git diff --name-only                           (6)
279               $ edit foo.c
280               $ git diff --name-only                           (7)
281               $ git update-index --no-assume-unchanged foo.c   (8)
282               $ git diff --name-only                           (9)
283               M foo.c
284
285           1. forces lstat(2) to set "assume unchanged" bits for paths that
286           match index.
287           2. mark the path to be edited.
288           3. this does lstat(2) and finds index matches the path.
289           4. this does lstat(2) and finds index does not match the path.
290           5. registering the new version to index sets "assume unchanged"
291           bit.
292           6. and it is assumed unchanged.
293           7. even after you edit it.
294           8. you can tell about the change after the fact.
295           9. now it checks with lstat(2) and finds it has been changed.
296

SKIP-WORKTREE BIT

298       Skip-worktree bit can be defined in one (long) sentence: When reading
299       an entry, if it is marked as skip-worktree, then Git pretends its
300       working directory version is up to date and read the index version
301       instead.
302
303       To elaborate, "reading" means checking for file existence, reading file
304       attributes or file content. The working directory version may be
305       present or absent. If present, its content may match against the index
306       version or not. Writing is not affected by this bit, content safety is
307       still first priority. Note that Git can update working directory file,
308       that is marked skip-worktree, if it is safe to do so (i.e. working
309       directory version matches index version)
310
311       Although this bit looks similar to assume-unchanged bit, its goal is
312       different from assume-unchanged bit’s. Skip-worktree also takes
313       precedence over assume-unchanged bit when both are set.
314

CONFIGURATION

316       The command honors core.filemode configuration variable. If your
317       repository is on a filesystem whose executable bits are unreliable,
318       this should be set to false (see git-config(1)). This causes the
319       command to ignore differences in file modes recorded in the index and
320       the file mode on the filesystem if they differ only on executable bit.
321       On such an unfortunate filesystem, you may need to use git update-index
322       --chmod=.
323
324       Quite similarly, if core.symlinks configuration variable is set to
325       false (see git-config(1)), symbolic links are checked out as plain
326       files, and this command does not modify a recorded file mode from
327       symbolic link to regular file.
328
329       The command looks at core.ignorestat configuration variable. See Using
330       "assume unchanged" bit section above.
331
332       The command also looks at core.trustctime configuration variable. It
333       can be useful when the inode change time is regularly modified by
334       something outside Git (file system crawlers and backup systems use
335       ctime for marking files processed) (see git-config(1)).
336

SEE ALSO

338       git-config(1), git-add(1), git-ls-files(1)
339

GIT

341       Part of the git(1) suite
342
343
344
345Git 1.8.3.1                       11/19/2018               GIT-UPDATE-INDEX(1)
Impressum