blob: 66be18ef36696c7422acd46510b16d756962fb8d [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-update-index(1)
2===================
3
4NAME
5----
Junio C Hamano7c73c662007-01-19 00:37:506git-update-index - Register file contents in the working tree to the index
Junio C Hamano1a4e8412005-12-27 08:17:237
8
9SYNOPSIS
10--------
Junio C Hamano7e9f6b72006-02-22 10:44:5511[verse]
Junio C Hamano1a4e8412005-12-27 08:17:2312'git-update-index'
Junio C Hamano46338f52006-05-04 00:46:4413 [--add] [--remove | --force-remove] [--replace]
14 [--refresh] [-q] [--unmerged] [--ignore-missing]
Junio C Hamano1a4e8412005-12-27 08:17:2315 [--cacheinfo <mode> <object> <file>]\*
16 [--chmod=(+|-)x]
Junio C Hamano7e9f6b72006-02-22 10:44:5517 [--assume-unchanged | --no-assume-unchanged]
Junio C Hamano8a0a21e2006-08-24 07:37:4518 [--really-refresh] [--unresolve] [--again | -g]
Junio C Hamano1a4e8412005-12-27 08:17:2319 [--info-only] [--index-info]
20 [-z] [--stdin]
21 [--verbose]
22 [--] [<file>]\*
23
24DESCRIPTION
25-----------
26Modifies the index or directory cache. Each file mentioned is updated
27into the index and any 'unmerged' or 'needs updating' state is
28cleared.
29
Junio C Hamano35738e82008-01-07 07:55:4630See also linkgit:git-add[1] for a more user-friendly way to do some of
Junio C Hamano3d30fd52007-05-08 00:32:5331the most common operations on the index.
32
Junio C Hamano1a4e8412005-12-27 08:17:2333The way "git-update-index" handles files it is told about can be modified
34using the various options:
35
36OPTIONS
37-------
38--add::
39If a specified file isn't in the index already then it's
40added.
41Default behaviour is to ignore new files.
42
43--remove::
44If a specified file is in the index but is missing then it's
45removed.
Junio C Hamano341071d2006-06-04 07:24:4846Default behavior is to ignore removed file.
Junio C Hamano1a4e8412005-12-27 08:17:2347
48--refresh::
49Looks at the current index and checks to see if merges or
50updates are needed by checking stat() information.
51
52-q::
53 Quiet. If --refresh finds that the index needs an update, the
54 default behavior is to error out. This option makes
55 git-update-index continue anyway.
56
57--unmerged::
58 If --refresh finds unmerged changes in the index, the default
Junio C Hamanoa77a5132007-06-08 16:13:4459 behavior is to error out. This option makes git-update-index
Junio C Hamano1a4e8412005-12-27 08:17:2360 continue anyway.
61
62--ignore-missing::
63Ignores missing files during a --refresh
64
65--cacheinfo <mode> <object> <path>::
66Directly insert the specified info into the index.
Junio C Hamanoa77a5132007-06-08 16:13:4467
Junio C Hamano1a4e8412005-12-27 08:17:2368--index-info::
69 Read index information from stdin.
70
71--chmod=(+|-)x::
Junio C Hamanoa77a5132007-06-08 16:13:4472 Set the execute permissions on the updated files.
Junio C Hamano1a4e8412005-12-27 08:17:2373
Junio C Hamano7e9f6b72006-02-22 10:44:5574--assume-unchanged, --no-assume-unchanged::
75When these flags are specified, the object name recorded
76for the paths are not updated. Instead, these options
77sets and unsets the "assume unchanged" bit for the
78paths. When the "assume unchanged" bit is on, git stops
79checking the working tree files for possible
80modifications, so you need to manually unset the bit to
81tell git when you change the working tree file. This is
82sometimes helpful when working with a big project on a
83filesystem that has very slow lstat(2) system call
84(e.g. cifs).
85
Junio C Hamano8a0a21e2006-08-24 07:37:4586--again, -g::
Junio C Hamano26a57372006-05-10 00:13:4087Runs `git-update-index` itself on the paths whose index
88entries are different from those from the `HEAD` commit.
89
Junio C Hamano46338f52006-05-04 00:46:4490--unresolve::
91Restores the 'unmerged' or 'needs updating' state of a
92file during a merge if it was cleared by accident.
93
Junio C Hamano1a4e8412005-12-27 08:17:2394--info-only::
95Do not create objects in the object database for all
96<file> arguments that follow this flag; just insert
97their object IDs into the index.
98
99--force-remove::
100Remove the file from the index even when the working directory
101still has such a file. (Implies --remove.)
102
103--replace::
104By default, when a file `path` exists in the index,
105git-update-index refuses an attempt to add `path/file`.
106Similarly if a file `path/file` exists, a file `path`
107cannot be added. With --replace flag, existing entries
108that conflicts with the entry being added are
109automatically removed with warning messages.
110
111--stdin::
112Instead of taking list of paths from the command line,
113read list of paths from the standard input. Paths are
114separated by LF (i.e. one path per line) by default.
115
116--verbose::
117 Report what is being added and removed from index.
118
119-z::
120Only meaningful with `--stdin`; paths are separated with
121NUL character instead of LF.
122
Junio C Hamano1bb569e2006-05-05 23:14:25123\--::
Junio C Hamano1a4e8412005-12-27 08:17:23124Do not interpret any more arguments as options.
125
126<file>::
127Files to act on.
128Note that files beginning with '.' are discarded. This includes
Junio C Hamanoa77a5132007-06-08 16:13:44129`./file` and `dir/./file`. If you don't want this, then use
Junio C Hamano1a4e8412005-12-27 08:17:23130cleaner names.
131The same applies to directories ending '/' and paths with '//'
132
133Using --refresh
134---------------
135'--refresh' does not calculate a new sha1 file or bring the index
136up-to-date for mode/content changes. But what it *does* do is to
137"re-match" the stat information of a file with the index, so that you
138can refresh the index for a file that hasn't been changed but where
139the stat entry is out of date.
140
141For example, you'd want to do this after doing a "git-read-tree", to link
142up the stat index details with the proper files.
143
144Using --cacheinfo or --info-only
145--------------------------------
146'--cacheinfo' is used to register a file that is not in the
147current working directory. This is useful for minimum-checkout
148merging.
149
150To pretend you have a file with mode and sha1 at path, say:
151
152----------------
153$ git-update-index --cacheinfo mode sha1 path
154----------------
155
156'--info-only' is used to register files without placing them in the object
157database. This is useful for status-only repositories.
158
159Both '--cacheinfo' and '--info-only' behave similarly: the index is updated
160but the object database isn't. '--cacheinfo' is useful when the object is
161in the database but the file isn't available locally. '--info-only' is
162useful when the file is available, but you do not wish to update the
163object database.
164
165
166Using --index-info
167------------------
168
169`--index-info` is a more powerful mechanism that lets you feed
170multiple entry definitions from the standard input, and designed
171specifically for scripts. It can take inputs of three formats:
172
173 . mode SP sha1 TAB path
174+
175The first format is what "git-apply --index-info"
176reports, and used to reconstruct a partial tree
177that is used for phony merge base tree when falling
178back on 3-way merge.
179
180 . mode SP type SP sha1 TAB path
181+
182The second format is to stuff git-ls-tree output
183into the index file.
184
185 . mode SP sha1 SP stage TAB path
186+
187This format is to put higher order stages into the
188index file and matches git-ls-files --stage output.
189
190To place a higher stage entry to the index, the path should
191first be removed by feeding a mode=0 entry for the path, and
192then feeding necessary input lines in the third format.
193
194For example, starting with this index:
195
196------------
197$ git ls-files -s
198100644 8a1218a1024a212bb3db30becd860315f9f3ac52 0 frotz
199------------
200
201you can feed the following input to `--index-info`:
202
203------------
204$ git update-index --index-info
2050 0000000000000000000000000000000000000000 frotz
206100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz
207100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz
208------------
209
210The first line of the input feeds 0 as the mode to remove the
211path; the SHA1 does not matter as long as it is well formatted.
212Then the second and third line feeds stage 1 and stage 2 entries
213for that path. After the above, we would end up with this:
214
215------------
216$ git ls-files -s
217100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz
218100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz
219------------
220
221
Junio C Hamanofb2ead32006-11-13 23:40:59222Using ``assume unchanged'' bit
223------------------------------
Junio C Hamano7e9f6b72006-02-22 10:44:55224
225Many operations in git depend on your filesystem to have an
226efficient `lstat(2)` implementation, so that `st_mtime`
227information for working tree files can be cheaply checked to see
228if the file contents have changed from the version recorded in
229the index file. Unfortunately, some filesystems have
230inefficient `lstat(2)`. If your filesystem is one of them, you
231can set "assume unchanged" bit to paths you have not changed to
232cause git not to do this check. Note that setting this bit on a
233path does not mean git will check the contents of the file to
234see if it has changed -- it makes git to omit any checking and
235assume it has *not* changed. When you make changes to working
236tree files, you have to explicitly tell git about it by dropping
237"assume unchanged" bit, either before or after you modify them.
238
239In order to set "assume unchanged" bit, use `--assume-unchanged`
240option. To unset, use `--no-assume-unchanged`.
241
242The command looks at `core.ignorestat` configuration variable. When
243this is true, paths updated with `git-update-index paths...` and
244paths updated with other git commands that update both index and
245working tree (e.g. `git-apply --index`, `git-checkout-index -u`,
246and `git-read-tree -u`) are automatically marked as "assume
247unchanged". Note that "assume unchanged" bit is *not* set if
248`git-update-index --refresh` finds the working tree file matches
249the index (use `git-update-index --really-refresh` if you want
250to mark them as "assume unchanged").
251
252
Junio C Hamano1a4e8412005-12-27 08:17:23253Examples
254--------
255To update and refresh only the files already checked out:
256
257----------------
258$ git-checkout-index -n -f -a && git-update-index --ignore-missing --refresh
259----------------
260
Junio C Hamanoc8d88c22006-04-29 07:02:01261On an inefficient filesystem with `core.ignorestat` set::
262+
Junio C Hamano7e9f6b72006-02-22 10:44:55263------------
Junio C Hamanoc8d88c22006-04-29 07:02:01264$ git update-index --really-refresh <1>
265$ git update-index --no-assume-unchanged foo.c <2>
266$ git diff --name-only <3>
Junio C Hamano7e9f6b72006-02-22 10:44:55267$ edit foo.c
Junio C Hamanoc8d88c22006-04-29 07:02:01268$ git diff --name-only <4>
Junio C Hamano7e9f6b72006-02-22 10:44:55269M foo.c
Junio C Hamanoc8d88c22006-04-29 07:02:01270$ git update-index foo.c <5>
271$ git diff --name-only <6>
Junio C Hamano7e9f6b72006-02-22 10:44:55272$ edit foo.c
Junio C Hamanoc8d88c22006-04-29 07:02:01273$ git diff --name-only <7>
274$ git update-index --no-assume-unchanged foo.c <8>
275$ git diff --name-only <9>
Junio C Hamano7e9f6b72006-02-22 10:44:55276M foo.c
Junio C Hamanoc8d88c22006-04-29 07:02:01277------------
278+
279<1> forces lstat(2) to set "assume unchanged" bits for paths that match index.
Junio C Hamano7e9f6b72006-02-22 10:44:55280<2> mark the path to be edited.
281<3> this does lstat(2) and finds index matches the path.
Junio C Hamanoc8d88c22006-04-29 07:02:01282<4> this does lstat(2) and finds index does *not* match the path.
Junio C Hamano7e9f6b72006-02-22 10:44:55283<5> registering the new version to index sets "assume unchanged" bit.
284<6> and it is assumed unchanged.
285<7> even after you edit it.
286<8> you can tell about the change after the fact.
287<9> now it checks with lstat(2) and finds it has been changed.
Junio C Hamano7e9f6b72006-02-22 10:44:55288
Junio C Hamano1a4e8412005-12-27 08:17:23289
290Configuration
291-------------
292
293The command honors `core.filemode` configuration variable. If
294your repository is on an filesystem whose executable bits are
Junio C Hamano35738e82008-01-07 07:55:46295unreliable, this should be set to 'false' (see linkgit:git-config[1]).
Junio C Hamano1a4e8412005-12-27 08:17:23296This causes the command to ignore differences in file modes recorded
297in the index and the file mode on the filesystem if they differ only on
298executable bit. On such an unfortunate filesystem, you may
299need to use `git-update-index --chmod=`.
300
Junio C Hamanoaa83a7d2007-03-05 02:37:29301Quite similarly, if `core.symlinks` configuration variable is set
Junio C Hamano35738e82008-01-07 07:55:46302to 'false' (see linkgit:git-config[1]), symbolic links are checked out
Junio C Hamanoaa83a7d2007-03-05 02:37:29303as plain files, and this command does not modify a recorded file mode
304from symbolic link to regular file.
305
Junio C Hamano7e9f6b72006-02-22 10:44:55306The command looks at `core.ignorestat` configuration variable. See
307'Using "assume unchanged" bit' section above.
308
Junio C Hamano1a4e8412005-12-27 08:17:23309
310See Also
311--------
Junio C Hamano35738e82008-01-07 07:55:46312linkgit:git-config[1],
313linkgit:git-add[1]
Junio C Hamano1a4e8412005-12-27 08:17:23314
315
316Author
317------
318Written by Linus Torvalds <torvalds@osdl.org>
319
320Documentation
321--------------
322Documentation by David Greaves, Junio C Hamano and the git-list <git@vger.kernel.org>.
323
324GIT
325---
Junio C Hamano35738e82008-01-07 07:55:46326Part of the linkgit:git[7] suite