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                    [--assume-unchanged | --no-assume-unchanged]
16                    [--skip-worktree | --no-skip-worktree]
17                    [--ignore-submodules]
18                    [--really-refresh] [--unresolve] [--again | -g]
19                    [--info-only] [--index-info]
20                    [-z] [--stdin]
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       --assume-unchanged, --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). You should remember that an
87           explicit git add operation will still cause the file to be
88           refreshed from the working tree. Git will fail (gracefully) in case
89           it needs to modify this file in the index e.g. when merging in a
90           commit; thus, in case the assumed-untracked file is changed
91           upstream, you will need to handle the situation manually.
92
93       --really-refresh
94           Like --refresh, but checks stat information unconditionally,
95           without regard to the "assume unchanged" setting.
96
97       --skip-worktree, --no-skip-worktree
98           When one of these flags is specified, the object name recorded for
99           the paths are not updated. Instead, these options set and unset the
100           "skip-worktree" bit for the paths. See section "Skip-worktree bit"
101           below for more information.
102
103       -g, --again
104           Runs git update-index itself on the paths whose index entries are
105           different from those from the HEAD commit.
106
107       --unresolve
108           Restores the unmerged or needs updating state of a file during a
109           merge if it was cleared by accident.
110
111       --info-only
112           Do not create objects in the object database for all <file>
113           arguments that follow this flag; just insert their object IDs into
114           the index.
115
116       --force-remove
117           Remove the file from the index even when the working directory
118           still has such a file. (Implies --remove.)
119
120       --replace
121           By default, when a file path exists in the index, git update-index
122           refuses an attempt to add path/file. Similarly if a file path/file
123           exists, a file path cannot be added. With --replace flag, existing
124           entries that conflict with the entry being added are automatically
125           removed with warning messages.
126
127       --stdin
128           Instead of taking list of paths from the command line, read list of
129           paths from the standard input. Paths are separated by LF (i.e. one
130           path per line) by default.
131
132       --verbose
133           Report what is being added and removed from index.
134
135       -z
136           Only meaningful with --stdin; paths are separated with NUL
137           character instead of LF.
138
139       --
140           Do not interpret any more arguments as options.
141
142       <file>
143           Files to act on. Note that files beginning with .  are discarded.
144           This includes ./file and dir/./file. If you don’t want this, then
145           use cleaner names. The same applies to directories ending / and
146           paths with //
147

USING --REFRESH

149       --refresh does not calculate a new sha1 file or bring the index
150       up-to-date for mode/content changes. But what it does do is to
151       "re-match" the stat information of a file with the index, so that you
152       can refresh the index for a file that hasn’t been changed but where the
153       stat entry is out of date.
154
155       For example, you’d want to do this after doing a git read-tree, to link
156       up the stat index details with the proper files.
157

USING --CACHEINFO OR --INFO-ONLY

159       --cacheinfo is used to register a file that is not in the current
160       working directory. This is useful for minimum-checkout merging.
161
162       To pretend you have a file with mode and sha1 at path, say:
163
164           $ git update-index --cacheinfo mode sha1 path
165
166
167       --info-only is used to register files without placing them in the
168       object database. This is useful for status-only repositories.
169
170       Both --cacheinfo and --info-only behave similarly: the index is updated
171       but the object database isn’t. --cacheinfo is useful when the object is
172       in the database but the file isn’t available locally. --info-only is
173       useful when the file is available, but you do not wish to update the
174       object database.
175

USING --INDEX-INFO

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

USING “ASSUME UNCHANGED” BIT

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

EXAMPLES

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

SKIP-WORKTREE BIT

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

CONFIGURATION

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

SEE ALSO

326       git-config(1), git-add(1)
327

AUTHOR

329       Written by Linus Torvalds <torvalds@osdl.org[1]>
330

DOCUMENTATION

332       Documentation by David Greaves, Junio C Hamano and the git-list
333       <git@vger.kernel.org[2]>.
334

GIT

336       Part of the git(1) suite
337

NOTES

339        1. torvalds@osdl.org
340           mailto:torvalds@osdl.org
341
342        2. git@vger.kernel.org
343           mailto:git@vger.kernel.org
344
345
346
347Git 1.7.1                         08/16/2017               GIT-UPDATE-INDEX(1)
Impressum