]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-update-index.txt
Git 2.6.4
[thirdparty/git.git] / Documentation / git-update-index.txt
CommitLineData
215a7ad1 1git-update-index(1)
2cf565c5 2===================
2cf565c5
DG
3
4NAME
5----
c3f0baac 6git-update-index - Register file contents in the working tree to the index
2cf565c5
DG
7
8
9SYNOPSIS
10--------
f9666adf 11[verse]
b1889c36 12'git update-index'
de5f2bf3
MK
13 [--add] [--remove | --force-remove] [--replace]
14 [--refresh] [-q] [--unmerged] [--ignore-missing]
ec160ae1 15 [(--cacheinfo <mode>,<object>,<file>)...]
5773c9f2 16 [--chmod=(+|-)x]
0460ed2c
FC
17 [--[no-]assume-unchanged]
18 [--[no-]skip-worktree]
5fdeacb0 19 [--ignore-submodules]
5cb2e162 20 [--[no-|force-]untracked-cache]
7099c9c7 21 [--really-refresh] [--unresolve] [--again | -g]
14470c0d 22 [--info-only] [--index-info]
69dec66b 23 [-z] [--stdin] [--index-version <n>]
14470c0d 24 [--verbose]
0adda936 25 [--] [<file>...]
2cf565c5
DG
26
27DESCRIPTION
28-----------
29Modifies the index or directory cache. Each file mentioned is updated
5f3aa197 30into the index and any 'unmerged' or 'needs updating' state is
2cf565c5
DG
31cleared.
32
5162e697 33See also linkgit:git-add[1] for a more user-friendly way to do some of
e701ccc3
MM
34the most common operations on the index.
35
0b444cdb 36The way 'git update-index' handles files it is told about can be modified
2cf565c5
DG
37using the various options:
38
39OPTIONS
40-------
41--add::
5f3aa197 42 If a specified file isn't in the index already then it's
2cf565c5
DG
43 added.
44 Default behaviour is to ignore new files.
45
46--remove::
5f3aa197 47 If a specified file is in the index but is missing then it's
2cf565c5 48 removed.
abda1ef5 49 Default behavior is to ignore removed file.
2cf565c5
DG
50
51--refresh::
5f3aa197 52 Looks at the current index and checks to see if merges or
2cf565c5
DG
53 updates are needed by checking stat() information.
54
14470c0d 55-q::
5f3aa197 56 Quiet. If --refresh finds that the index needs an update, the
14470c0d 57 default behavior is to error out. This option makes
0b444cdb 58 'git update-index' continue anyway.
14470c0d 59
04c8ce9c 60--ignore-submodules::
5fdeacb0
JS
61 Do not try to update submodules. This option is only respected
62 when passed before --refresh.
63
14470c0d 64--unmerged::
5f3aa197 65 If --refresh finds unmerged changes in the index, the default
0b444cdb 66 behavior is to error out. This option makes 'git update-index'
14470c0d
CS
67 continue anyway.
68
2cf565c5
DG
69--ignore-missing::
70 Ignores missing files during a --refresh
71
ec160ae1 72--cacheinfo <mode>,<object>,<path>::
2cf565c5 73--cacheinfo <mode> <object> <path>::
ec160ae1
JH
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.
a6080a0a 78
14470c0d 79--index-info::
7acab8f1 80 Read index information from stdin.
14470c0d
CS
81
82--chmod=(+|-)x::
a6080a0a 83 Set the execute permissions on the updated files.
14470c0d 84
0460ed2c 85--[no-]assume-unchanged::
ccadb25f
PO
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
f9666adf
JH
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).
6259ac66 97+
6259ac66
PB
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.
f9666adf 102
466d1f15
ŠN
103--really-refresh::
104 Like '--refresh', but checks stat information unconditionally,
105 without regard to the "assume unchanged" setting.
106
0460ed2c 107--[no-]skip-worktree::
44a36913
NTND
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
3240240f
SB
113-g::
114--again::
0b444cdb 115 Runs 'git update-index' itself on the paths whose index
83e77a25
JH
116 entries are different from those from the `HEAD` commit.
117
060729dd
MK
118--unresolve::
119 Restores the 'unmerged' or 'needs updating' state of a
120 file during a merge if it was cleared by accident.
121
df6e1516
BL
122--info-only::
123 Do not create objects in the object database for all
124 <file> arguments that follow this flag; just insert
5f3aa197 125 their object IDs into the index.
df6e1516 126
2cf565c5
DG
127--force-remove::
128 Remove the file from the index even when the working directory
9b63f501 129 still has such a file. (Implies --remove.)
2cf565c5
DG
130
131--replace::
132 By default, when a file `path` exists in the index,
0b444cdb 133 'git update-index' refuses an attempt to add `path/file`.
2cf565c5
DG
134 Similarly if a file `path/file` exists, a file `path`
135 cannot be added. With --replace flag, existing entries
04c8ce9c 136 that conflict with the entry being added are
2cf565c5
DG
137 automatically removed with warning messages.
138
1f7f99de
JH
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
14470c0d
CS
144--verbose::
145 Report what is being added and removed from index.
146
69dec66b
JH
147--index-version <n>::
148 Write the resulting index out in the named on-disk format version.
647d8794
NTND
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.
69dec66b 158
1f7f99de 159-z::
537497be
BW
160 Only meaningful with `--stdin` or `--index-info`; paths are
161 separated with NUL character instead of LF.
1f7f99de 162
c18b80a0
NTND
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
f745acb0 172 indexes that take a significant amount of time to read or write.
c18b80a0 173
9e597241
NTND
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
f64cb88d
NTND
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
e994004f 188\--::
2cf565c5
DG
189 Do not interpret any more arguments as options.
190
191<file>::
192 Files to act on.
5773c9f2 193 Note that files beginning with '.' are discarded. This includes
a6080a0a 194 `./file` and `dir/./file`. If you don't want this, then use
2cf565c5
DG
195 cleaner names.
196 The same applies to directories ending '/' and paths with '//'
197
198Using --refresh
199---------------
5f3aa197 200'--refresh' does not calculate a new sha1 file or bring the index
2cf565c5 201up-to-date for mode/content changes. But what it *does* do is to
5f3aa197
LS
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
2cf565c5
DG
204the stat entry is out of date.
205
0b444cdb 206For example, you'd want to do this after doing a 'git read-tree', to link
5f3aa197 207up the stat index details with the proper files.
2cf565c5 208
df6e1516
BL
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
df8baa42 215To pretend you have a file with mode and sha1 at path, say:
2cf565c5 216
61f693bd 217----------------
7ac92f64 218$ git update-index --cacheinfo <mode>,<sha1>,<path>
61f693bd 219----------------
2cf565c5 220
df6e1516
BL
221'--info-only' is used to register files without placing them in the object
222database. This is useful for status-only repositories.
2cf565c5 223
df6e1516
BL
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
d23748a6
JH
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+
0b444cdb 247The second format is to stuff 'git ls-tree' output
d23748a6
JH
248into the index file.
249
250 . mode SP sha1 SP stage TAB path
251+
252This format is to put higher order stages into the
0b444cdb 253index file and matches 'git ls-files --stage' output.
d23748a6
JH
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
d5fa1f1a 276path; the SHA-1 does not matter as long as it is well formatted.
d23748a6
JH
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
bae777db
JF
287Using ``assume unchanged'' bit
288------------------------------
f9666adf 289
2de9b711 290Many operations in Git depend on your filesystem to have an
f9666adf
JH
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
2de9b711
TA
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
f9666adf 300assume it has *not* changed. When you make changes to working
2de9b711 301tree files, you have to explicitly tell Git about it by dropping
f9666adf
JH
302"assume unchanged" bit, either before or after you modify them.
303
304In order to set "assume unchanged" bit, use `--assume-unchanged`
acd6d7e7
SN
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]).
f9666adf
JH
308
309The command looks at `core.ignorestat` configuration variable. When
b1889c36 310this is true, paths updated with `git update-index paths...` and
2de9b711 311paths updated with other Git commands that update both index and
0b444cdb
TR
312working tree (e.g. 'git apply --index', 'git checkout-index -u',
313and 'git read-tree -u') are automatically marked as "assume
f9666adf 314unchanged". Note that "assume unchanged" bit is *not* set if
b1889c36
JN
315`git update-index --refresh` finds the working tree file matches
316the index (use `git update-index --really-refresh` if you want
f9666adf
JH
317to mark them as "assume unchanged").
318
319
df6e1516
BL
320Examples
321--------
2cf565c5
DG
322To update and refresh only the files already checked out:
323
61f693bd 324----------------
b1889c36 325$ git checkout-index -n -f -a && git update-index --ignore-missing --refresh
61f693bd 326----------------
2cf565c5 327
48aeecdc
SE
328On an inefficient filesystem with `core.ignorestat` set::
329+
f9666adf 330------------
48aeecdc
SE
331$ git update-index --really-refresh <1>
332$ git update-index --no-assume-unchanged foo.c <2>
333$ git diff --name-only <3>
f9666adf 334$ edit foo.c
48aeecdc 335$ git diff --name-only <4>
f9666adf 336M foo.c
48aeecdc
SE
337$ git update-index foo.c <5>
338$ git diff --name-only <6>
f9666adf 339$ edit foo.c
48aeecdc
SE
340$ git diff --name-only <7>
341$ git update-index --no-assume-unchanged foo.c <8>
342$ git diff --name-only <9>
f9666adf 343M foo.c
48aeecdc
SE
344------------
345+
346<1> forces lstat(2) to set "assume unchanged" bits for paths that match index.
f9666adf
JH
347<2> mark the path to be edited.
348<3> this does lstat(2) and finds index matches the path.
48aeecdc 349<4> this does lstat(2) and finds index does *not* match the path.
f9666adf
JH
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.
f9666adf 355
2cf565c5 356
44a36913
NTND
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
5773c9f2
JH
378Configuration
379-------------
380
381The command honors `core.filemode` configuration variable. If
466d1f15 382your repository is on a filesystem whose executable bits are
5162e697 383unreliable, this should be set to 'false' (see linkgit:git-config[1]).
61f693bd
JL
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
5773c9f2 386executable bit. On such an unfortunate filesystem, you may
0b444cdb 387need to use 'git update-index --chmod='.
5773c9f2 388
78a8d641 389Quite similarly, if `core.symlinks` configuration variable is set
5162e697 390to 'false' (see linkgit:git-config[1]), symbolic links are checked out
78a8d641
JS
391as plain files, and this command does not modify a recorded file mode
392from symbolic link to regular file.
393
f9666adf
JH
394The command looks at `core.ignorestat` configuration variable. See
395'Using "assume unchanged" bit' section above.
396
1ce4790b
AR
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
61f693bd 402
56ae8df5 403SEE ALSO
61f693bd 404--------
5162e697 405linkgit:git-config[1],
acd6d7e7
SN
406linkgit:git-add[1],
407linkgit:git-ls-files[1]
61f693bd 408
2cf565c5
DG
409GIT
410---
9e1f0a85 411Part of the linkgit:git[1] suite