blob: f4bb9c5daf95c6669210429d7a560565dadc91d5 [file] [log] [blame]
Junio C Hamano215a7ad2005-09-07 17:26:23 -07001git-update-index(1)
David Greaves2cf565c2005-05-10 22:32:30 +01002===================
David Greaves2cf565c2005-05-10 22:32:30 +01003
4NAME
5----
Junio C Hamanoc3f0baa2007-01-18 15:53:37 -08006git-update-index - Register file contents in the working tree to the index
David Greaves2cf565c2005-05-10 22:32:30 +01007
8
9SYNOPSIS
10--------
Junio C Hamanof9666ad2006-02-12 01:48:47 -080011[verse]
Jonathan Niederb1889c32008-06-30 01:09:04 -050012'git update-index'
Matthias Kestenholzde5f2bf2006-05-03 12:51:40 +020013 [--add] [--remove | --force-remove] [--replace]
14 [--refresh] [-q] [--unmerged] [--ignore-missing]
Junio C Hamanoec160ae2014-03-23 16:57:28 -070015 [(--cacheinfo <mode>,<object>,<file>)...]
Junio C Hamano5773c9f2005-10-29 14:32:56 -070016 [--chmod=(+|-)x]
Felipe Contreras0460ed22013-05-08 20:16:55 -050017 [--[no-]assume-unchanged]
18 [--[no-]skip-worktree]
Johannes Schindelin8dfb04a2019-10-30 10:49:37 +000019 [--[no-]ignore-skip-worktree-entries]
Ben Peart780494b2017-09-22 12:35:41 -040020 [--[no-]fsmonitor-valid]
Johannes Schindelin5fdeacb2008-05-14 18:03:45 +010021 [--ignore-submodules]
Christian Couderbc497122015-11-25 10:30:02 +010022 [--[no-]split-index]
Christian Coudereaab83d2016-01-24 16:28:16 +010023 [--[no-|test-|force-]untracked-cache]
Ben Peart780494b2017-09-22 12:35:41 -040024 [--[no-]fsmonitor]
Junio C Hamano7099c9c2006-08-23 21:24:47 -070025 [--really-refresh] [--unresolve] [--again | -g]
Chris Shoemaker14470c02005-10-29 17:46:41 -040026 [--info-only] [--index-info]
Junio C Hamano69dec662012-04-04 09:37:02 -070027 [-z] [--stdin] [--index-version <n>]
Chris Shoemaker14470c02005-10-29 17:46:41 -040028 [--verbose]
Štěpán Němec0adda932010-10-08 19:31:17 +020029 [--] [<file>...]
David Greaves2cf565c2005-05-10 22:32:30 +010030
31DESCRIPTION
32-----------
Utku Gultopub356d232021-01-08 16:54:56 +000033Modifies the index. Each file mentioned is updated into the index and
34any 'unmerged' or 'needs updating' state is cleared.
David Greaves2cf565c2005-05-10 22:32:30 +010035
Dan McGee5162e692007-12-29 00:20:38 -060036See also linkgit:git-add[1] for a more user-friendly way to do some of
Matthieu Moye701ccc2007-05-06 23:11:56 +020037the most common operations on the index.
38
Thomas Rast0b444cd2010-01-10 00:33:00 +010039The way 'git update-index' handles files it is told about can be modified
David Greaves2cf565c2005-05-10 22:32:30 +010040using the various options:
41
42OPTIONS
43-------
44--add::
Lukas_Sandström5f3aa192005-11-11 02:12:27 +010045 If a specified file isn't in the index already then it's
David Greaves2cf565c2005-05-10 22:32:30 +010046 added.
47 Default behaviour is to ignore new files.
48
49--remove::
Lukas_Sandström5f3aa192005-11-11 02:12:27 +010050 If a specified file is in the index but is missing then it's
David Greaves2cf565c2005-05-10 22:32:30 +010051 removed.
Horst H. von Brandabda1ef2006-06-03 16:27:26 -040052 Default behavior is to ignore removed file.
David Greaves2cf565c2005-05-10 22:32:30 +010053
54--refresh::
Lukas_Sandström5f3aa192005-11-11 02:12:27 +010055 Looks at the current index and checks to see if merges or
David Greaves2cf565c2005-05-10 22:32:30 +010056 updates are needed by checking stat() information.
57
Chris Shoemaker14470c02005-10-29 17:46:41 -040058-q::
Lukas_Sandström5f3aa192005-11-11 02:12:27 +010059 Quiet. If --refresh finds that the index needs an update, the
Chris Shoemaker14470c02005-10-29 17:46:41 -040060 default behavior is to error out. This option makes
Thomas Rast0b444cd2010-01-10 00:33:00 +010061 'git update-index' continue anyway.
Chris Shoemaker14470c02005-10-29 17:46:41 -040062
Markus Heidelberg04c8ce92008-12-19 13:14:18 +010063--ignore-submodules::
Johannes Schindelin5fdeacb2008-05-14 18:03:45 +010064 Do not try to update submodules. This option is only respected
65 when passed before --refresh.
66
Chris Shoemaker14470c02005-10-29 17:46:41 -040067--unmerged::
Lukas_Sandström5f3aa192005-11-11 02:12:27 +010068 If --refresh finds unmerged changes in the index, the default
Thomas Rast0b444cd2010-01-10 00:33:00 +010069 behavior is to error out. This option makes 'git update-index'
Chris Shoemaker14470c02005-10-29 17:46:41 -040070 continue anyway.
71
David Greaves2cf565c2005-05-10 22:32:30 +010072--ignore-missing::
73 Ignores missing files during a --refresh
74
Junio C Hamanoec160ae2014-03-23 16:57:28 -070075--cacheinfo <mode>,<object>,<path>::
David Greaves2cf565c2005-05-10 22:32:30 +010076--cacheinfo <mode> <object> <path>::
Junio C Hamanoec160ae2014-03-23 16:57:28 -070077 Directly insert the specified info into the index. For
78 backward compatibility, you can also give these three
79 arguments as three separate parameters, but new users are
80 encouraged to use a single-parameter form.
Junio C Hamanoa6080a02007-06-07 00:04:01 -070081
Chris Shoemaker14470c02005-10-29 17:46:41 -040082--index-info::
Nikolai Weibull7acab8f2005-11-15 00:20:01 +010083 Read index information from stdin.
Chris Shoemaker14470c02005-10-29 17:46:41 -040084
85--chmod=(+|-)x::
Junio C Hamanoa6080a02007-06-07 00:04:01 -070086 Set the execute permissions on the updated files.
Chris Shoemaker14470c02005-10-29 17:46:41 -040087
Felipe Contreras0460ed22013-05-08 20:16:55 -050088--[no-]assume-unchanged::
Philip Oakleyccadb252014-12-06 15:04:30 +000089 When this flag is specified, the object names recorded
90 for the paths are not updated. Instead, this option
91 sets/unsets the "assume unchanged" bit for the
92 paths. When the "assume unchanged" bit is on, the user
93 promises not to change the file and allows Git to assume
94 that the working tree file matches what is recorded in
95 the index. If you want to change the working tree file,
96 you need to unset the bit to tell Git. This is
Junio C Hamanof9666ad2006-02-12 01:48:47 -080097 sometimes helpful when working with a big project on a
98 filesystem that has very slow lstat(2) system call
99 (e.g. cifs).
Petr Baudis6259ac62008-07-18 16:11:07 +0200100+
Petr Baudis6259ac62008-07-18 16:11:07 +0200101Git will fail (gracefully) in case it needs to modify this file
102in the index e.g. when merging in a commit;
103thus, in case the assumed-untracked file is changed upstream,
104you will need to handle the situation manually.
Junio C Hamanof9666ad2006-02-12 01:48:47 -0800105
Štěpán Němec466d1f12009-11-10 19:11:51 +0100106--really-refresh::
Matthieu Moybcf96262016-06-28 13:40:11 +0200107 Like `--refresh`, but checks stat information unconditionally,
Štěpán Němec466d1f12009-11-10 19:11:51 +0100108 without regard to the "assume unchanged" setting.
109
Felipe Contreras0460ed22013-05-08 20:16:55 -0500110--[no-]skip-worktree::
Nguyễn Thái Ngọc Duy44a36912009-08-20 20:46:57 +0700111 When one of these flags is specified, the object name recorded
112 for the paths are not updated. Instead, these options
113 set and unset the "skip-worktree" bit for the paths. See
114 section "Skip-worktree bit" below for more information.
115
Johannes Schindelin8dfb04a2019-10-30 10:49:37 +0000116
117--[no-]ignore-skip-worktree-entries::
118 Do not remove skip-worktree (AKA "index-only") entries even when
119 the `--remove` option was specified.
120
Ben Peart780494b2017-09-22 12:35:41 -0400121--[no-]fsmonitor-valid::
122 When one of these flags is specified, the object name recorded
123 for the paths are not updated. Instead, these options
124 set and unset the "fsmonitor valid" bit for the paths. See
125 section "File System Monitor" below for more information.
126
Stephan Beyer32402402008-06-08 03:36:09 +0200127-g::
128--again::
Thomas Rast0b444cd2010-01-10 00:33:00 +0100129 Runs 'git update-index' itself on the paths whose index
Junio C Hamano83e77a22006-05-05 17:40:47 -0700130 entries are different from those from the `HEAD` commit.
131
Matthias Kestenholz060729d2006-05-03 12:53:19 +0200132--unresolve::
133 Restores the 'unmerged' or 'needs updating' state of a
134 file during a merge if it was cleared by accident.
135
Bryan Larsendf6e1512005-07-08 16:52:12 -0700136--info-only::
137 Do not create objects in the object database for all
138 <file> arguments that follow this flag; just insert
Lukas_Sandström5f3aa192005-11-11 02:12:27 +0100139 their object IDs into the index.
Bryan Larsendf6e1512005-07-08 16:52:12 -0700140
David Greaves2cf565c2005-05-10 22:32:30 +0100141--force-remove::
142 Remove the file from the index even when the working directory
Petr Baudis9b63f502005-05-31 18:52:43 +0200143 still has such a file. (Implies --remove.)
David Greaves2cf565c2005-05-10 22:32:30 +0100144
145--replace::
146 By default, when a file `path` exists in the index,
Thomas Rast0b444cd2010-01-10 00:33:00 +0100147 'git update-index' refuses an attempt to add `path/file`.
David Greaves2cf565c2005-05-10 22:32:30 +0100148 Similarly if a file `path/file` exists, a file `path`
149 cannot be added. With --replace flag, existing entries
Markus Heidelberg04c8ce92008-12-19 13:14:18 +0100150 that conflict with the entry being added are
David Greaves2cf565c2005-05-10 22:32:30 +0100151 automatically removed with warning messages.
152
Junio C Hamano1f7f99d2005-09-26 18:13:32 -0700153--stdin::
154 Instead of taking list of paths from the command line,
155 read list of paths from the standard input. Paths are
156 separated by LF (i.e. one path per line) by default.
157
Chris Shoemaker14470c02005-10-29 17:46:41 -0400158--verbose::
159 Report what is being added and removed from index.
160
Junio C Hamano69dec662012-04-04 09:37:02 -0700161--index-version <n>::
162 Write the resulting index out in the named on-disk format version.
Nguyễn Thái Ngọc Duy647d8792013-02-23 09:29:31 +0700163 Supported versions are 2, 3 and 4. The current default version is 2
164 or 3, depending on whether extra features are used, such as
165 `git add -N`.
166+
167Version 4 performs a simple pathname compression that reduces index
168size by 30%-50% on large repositories, which results in faster load
Evan Zacksbe945682017-09-12 15:58:39 -0700169time. Version 4 is relatively young (first released in 1.8.0 in
Nguyễn Thái Ngọc Duy647d8792013-02-23 09:29:31 +0700170October 2012). Other Git implementations such as JGit and libgit2
171may not support it yet.
Junio C Hamano69dec662012-04-04 09:37:02 -0700172
Junio C Hamano1f7f99d2005-09-26 18:13:32 -0700173-z::
Bert Wesarg537497b2010-10-08 08:50:20 +0200174 Only meaningful with `--stdin` or `--index-info`; paths are
175 separated with NUL character instead of LF.
Junio C Hamano1f7f99d2005-09-26 18:13:32 -0700176
Nguyễn Thái Ngọc Duyc18b80a2014-06-13 19:19:44 +0700177--split-index::
178--no-split-index::
Christian Couderb4601392017-03-06 10:42:03 +0100179 Enable or disable split index mode. If split-index mode is
180 already enabled and `--split-index` is given again, all
181 changes in $GIT_DIR/index are pushed back to the shared index
182 file.
Christian Couder13c0e4c2017-02-27 19:00:06 +0100183+
184These options take effect whatever the value of the `core.splitIndex`
185configuration variable (see linkgit:git-config[1]). But a warning is
186emitted when the change goes against the configured value, as the
187configured value will take effect next time the index is read and this
188will remove the intended effect of the option.
Nguyễn Thái Ngọc Duyc18b80a2014-06-13 19:19:44 +0700189
Nguyễn Thái Ngọc Duy9e597242015-03-08 17:12:42 +0700190--untracked-cache::
191--no-untracked-cache::
Christian Couder435ec092016-01-27 07:58:05 +0100192 Enable or disable untracked cache feature. Please use
193 `--test-untracked-cache` before enabling it.
194+
195These options take effect whatever the value of the `core.untrackedCache`
196configuration variable (see linkgit:git-config[1]). But a warning is
197emitted when the change goes against the configured value, as the
198configured value will take effect next time the index is read and this
199will remove the intended effect of the option.
Nguyễn Thái Ngọc Duy9e597242015-03-08 17:12:42 +0700200
Christian Coudereaab83d2016-01-24 16:28:16 +0100201--test-untracked-cache::
202 Only perform tests on the working directory to make sure
203 untracked cache can be used. You have to manually enable
Christian Couder435ec092016-01-27 07:58:05 +0100204 untracked cache using `--untracked-cache` or
205 `--force-untracked-cache` or the `core.untrackedCache`
206 configuration variable afterwards if you really want to use
207 it. If a test fails the exit code is 1 and a message
208 explains what is not working as needed, otherwise the exit
209 code is 0 and OK is printed.
Christian Coudereaab83d2016-01-24 16:28:16 +0100210
Nguyễn Thái Ngọc Duyf64cb882015-03-08 17:12:43 +0700211--force-untracked-cache::
Christian Couder435ec092016-01-27 07:58:05 +0100212 Same as `--untracked-cache`. Provided for backwards
213 compatibility with older versions of Git where
214 `--untracked-cache` used to imply `--test-untracked-cache` but
215 this option would enable the extension unconditionally.
Nguyễn Thái Ngọc Duyf64cb882015-03-08 17:12:43 +0700216
Ben Peart780494b2017-09-22 12:35:41 -0400217--fsmonitor::
218--no-fsmonitor::
219 Enable or disable files system monitor feature. These options
220 take effect whatever the value of the `core.fsmonitor`
221 configuration variable (see linkgit:git-config[1]). But a warning
222 is emitted when the change goes against the configured value, as
223 the configured value will take effect next time the index is
224 read and this will remove the intended effect of the option.
225
seane9940042006-05-05 15:05:24 -0400226\--::
David Greaves2cf565c2005-05-10 22:32:30 +0100227 Do not interpret any more arguments as options.
228
229<file>::
230 Files to act on.
Junio C Hamano5773c9f2005-10-29 14:32:56 -0700231 Note that files beginning with '.' are discarded. This includes
Junio C Hamanoa6080a02007-06-07 00:04:01 -0700232 `./file` and `dir/./file`. If you don't want this, then use
David Greaves2cf565c2005-05-10 22:32:30 +0100233 cleaner names.
234 The same applies to directories ending '/' and paths with '//'
235
Nguyễn Thái Ngọc Duy76a87882018-04-30 17:35:33 +0200236USING --REFRESH
David Greaves2cf565c2005-05-10 22:32:30 +0100237---------------
Matthieu Moybcf96262016-06-28 13:40:11 +0200238`--refresh` does not calculate a new sha1 file or bring the index
Martin Ågren7560f542017-08-23 19:49:35 +0200239up to date for mode/content changes. But what it *does* do is to
Lukas_Sandström5f3aa192005-11-11 02:12:27 +0100240"re-match" the stat information of a file with the index, so that you
241can refresh the index for a file that hasn't been changed but where
David Greaves2cf565c2005-05-10 22:32:30 +0100242the stat entry is out of date.
243
Thomas Rast0b444cd2010-01-10 00:33:00 +0100244For example, you'd want to do this after doing a 'git read-tree', to link
Lukas_Sandström5f3aa192005-11-11 02:12:27 +0100245up the stat index details with the proper files.
David Greaves2cf565c2005-05-10 22:32:30 +0100246
Nguyễn Thái Ngọc Duy76a87882018-04-30 17:35:33 +0200247USING --CACHEINFO OR --INFO-ONLY
Bryan Larsendf6e1512005-07-08 16:52:12 -0700248--------------------------------
Matthieu Moybcf96262016-06-28 13:40:11 +0200249`--cacheinfo` is used to register a file that is not in the
Bryan Larsendf6e1512005-07-08 16:52:12 -0700250current working directory. This is useful for minimum-checkout
251merging.
David Greaves2cf565c2005-05-10 22:32:30 +0100252
Elijah Newren388d0ff2018-08-08 13:28:07 -0700253To pretend you have a file at path with mode and sha1, say:
David Greaves2cf565c2005-05-10 22:32:30 +0100254
Jon Loeliger61f693b2005-12-05 23:13:03 -0600255----------------
Elijah Newren388d0ff2018-08-08 13:28:07 -0700256$ git update-index --add --cacheinfo <mode>,<sha1>,<path>
Jon Loeliger61f693b2005-12-05 23:13:03 -0600257----------------
David Greaves2cf565c2005-05-10 22:32:30 +0100258
Matthieu Moybcf96262016-06-28 13:40:11 +0200259`--info-only` is used to register files without placing them in the object
Bryan Larsendf6e1512005-07-08 16:52:12 -0700260database. This is useful for status-only repositories.
261
Matthieu Moybcf96262016-06-28 13:40:11 +0200262Both `--cacheinfo` and `--info-only` behave similarly: the index is updated
263but the object database isn't. `--cacheinfo` is useful when the object is
264in the database but the file isn't available locally. `--info-only` is
Bryan Larsendf6e1512005-07-08 16:52:12 -0700265useful when the file is available, but you do not wish to update the
266object database.
267
Junio C Hamanod23748a2005-12-07 01:45:38 -0800268
Nguyễn Thái Ngọc Duy76a87882018-04-30 17:35:33 +0200269USING --INDEX-INFO
Junio C Hamanod23748a2005-12-07 01:45:38 -0800270------------------
271
272`--index-info` is a more powerful mechanism that lets you feed
273multiple entry definitions from the standard input, and designed
274specifically for scripts. It can take inputs of three formats:
275
Junio C Hamanod23748a2005-12-07 01:45:38 -0800276 . mode SP type SP sha1 TAB path
277+
Junio C Hamanoe05aa682018-08-08 14:35:18 -0700278This format is to stuff `git ls-tree` output into the index.
Junio C Hamanod23748a2005-12-07 01:45:38 -0800279
280 . mode SP sha1 SP stage TAB path
281+
282This format is to put higher order stages into the
Thomas Rast0b444cd2010-01-10 00:33:00 +0100283index file and matches 'git ls-files --stage' output.
Junio C Hamanod23748a2005-12-07 01:45:38 -0800284
Junio C Hamanoe05aa682018-08-08 14:35:18 -0700285 . mode SP sha1 TAB path
286+
287This format is no longer produced by any Git command, but is
288and will continue to be supported by `update-index --index-info`.
289
Junio C Hamanod23748a2005-12-07 01:45:38 -0800290To place a higher stage entry to the index, the path should
291first be removed by feeding a mode=0 entry for the path, and
292then feeding necessary input lines in the third format.
293
294For example, starting with this index:
295
296------------
297$ git ls-files -s
298100644 8a1218a1024a212bb3db30becd860315f9f3ac52 0 frotz
299------------
300
301you can feed the following input to `--index-info`:
302
303------------
304$ git update-index --index-info
3050 0000000000000000000000000000000000000000 frotz
306100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz
307100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz
308------------
309
310The first line of the input feeds 0 as the mode to remove the
Thomas Ackermannd5fa1f12013-04-15 19:49:04 +0200311path; the SHA-1 does not matter as long as it is well formatted.
Junio C Hamanod23748a2005-12-07 01:45:38 -0800312Then the second and third line feeds stage 1 and stage 2 entries
313for that path. After the above, we would end up with this:
314
315------------
316$ git ls-files -s
317100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz
318100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz
319------------
320
321
Nguyễn Thái Ngọc Duy76a87882018-04-30 17:35:33 +0200322USING ``ASSUME UNCHANGED'' BIT
Jonas Fonsecabae777d2006-11-12 22:28:43 +0100323------------------------------
Junio C Hamanof9666ad2006-02-12 01:48:47 -0800324
Thomas Ackermann2de9b712013-01-21 20:17:53 +0100325Many operations in Git depend on your filesystem to have an
Junio C Hamanof9666ad2006-02-12 01:48:47 -0800326efficient `lstat(2)` implementation, so that `st_mtime`
327information for working tree files can be cheaply checked to see
328if the file contents have changed from the version recorded in
329the index file. Unfortunately, some filesystems have
330inefficient `lstat(2)`. If your filesystem is one of them, you
331can set "assume unchanged" bit to paths you have not changed to
Thomas Ackermann2de9b712013-01-21 20:17:53 +0100332cause Git not to do this check. Note that setting this bit on a
333path does not mean Git will check the contents of the file to
334see if it has changed -- it makes Git to omit any checking and
Junio C Hamanof9666ad2006-02-12 01:48:47 -0800335assume it has *not* changed. When you make changes to working
Thomas Ackermann2de9b712013-01-21 20:17:53 +0100336tree files, you have to explicitly tell Git about it by dropping
Junio C Hamanof9666ad2006-02-12 01:48:47 -0800337"assume unchanged" bit, either before or after you modify them.
338
339In order to set "assume unchanged" bit, use `--assume-unchanged`
Stefan Naeweacd6d7e2011-09-21 08:21:50 +0200340option. To unset, use `--no-assume-unchanged`. To see which files
341have the "assume unchanged" bit set, use `git ls-files -v`
342(see linkgit:git-ls-files[1]).
Junio C Hamanof9666ad2006-02-12 01:48:47 -0800343
344The command looks at `core.ignorestat` configuration variable. When
Jonathan Niederb1889c32008-06-30 01:09:04 -0500345this is true, paths updated with `git update-index paths...` and
Thomas Ackermann2de9b712013-01-21 20:17:53 +0100346paths updated with other Git commands that update both index and
Thomas Rast0b444cd2010-01-10 00:33:00 +0100347working tree (e.g. 'git apply --index', 'git checkout-index -u',
348and 'git read-tree -u') are automatically marked as "assume
Junio C Hamanof9666ad2006-02-12 01:48:47 -0800349unchanged". Note that "assume unchanged" bit is *not* set if
Jonathan Niederb1889c32008-06-30 01:09:04 -0500350`git update-index --refresh` finds the working tree file matches
351the index (use `git update-index --really-refresh` if you want
Junio C Hamanof9666ad2006-02-12 01:48:47 -0800352to mark them as "assume unchanged").
353
Elijah Newren90235352022-01-14 15:59:42 +0000354Sometimes users confuse the assume-unchanged bit with the
355skip-worktree bit. See the final paragraph in the "Skip-worktree bit"
356section below for an explanation of the differences.
357
Junio C Hamanof9666ad2006-02-12 01:48:47 -0800358
Nguyễn Thái Ngọc Duy76a87882018-04-30 17:35:33 +0200359EXAMPLES
Bryan Larsendf6e1512005-07-08 16:52:12 -0700360--------
David Greaves2cf565c2005-05-10 22:32:30 +0100361To update and refresh only the files already checked out:
362
Jon Loeliger61f693b2005-12-05 23:13:03 -0600363----------------
Jonathan Niederb1889c32008-06-30 01:09:04 -0500364$ git checkout-index -n -f -a && git update-index --ignore-missing --refresh
Jon Loeliger61f693b2005-12-05 23:13:03 -0600365----------------
David Greaves2cf565c2005-05-10 22:32:30 +0100366
Sean Estabrooks48aeecd2006-04-28 09:15:05 -0400367On an inefficient filesystem with `core.ignorestat` set::
368+
Junio C Hamanof9666ad2006-02-12 01:48:47 -0800369------------
Sean Estabrooks48aeecd2006-04-28 09:15:05 -0400370$ git update-index --really-refresh <1>
371$ git update-index --no-assume-unchanged foo.c <2>
372$ git diff --name-only <3>
Junio C Hamanof9666ad2006-02-12 01:48:47 -0800373$ edit foo.c
Sean Estabrooks48aeecd2006-04-28 09:15:05 -0400374$ git diff --name-only <4>
Junio C Hamanof9666ad2006-02-12 01:48:47 -0800375M foo.c
Sean Estabrooks48aeecd2006-04-28 09:15:05 -0400376$ git update-index foo.c <5>
377$ git diff --name-only <6>
Junio C Hamanof9666ad2006-02-12 01:48:47 -0800378$ edit foo.c
Sean Estabrooks48aeecd2006-04-28 09:15:05 -0400379$ git diff --name-only <7>
380$ git update-index --no-assume-unchanged foo.c <8>
381$ git diff --name-only <9>
Junio C Hamanof9666ad2006-02-12 01:48:47 -0800382M foo.c
Sean Estabrooks48aeecd2006-04-28 09:15:05 -0400383------------
384+
385<1> forces lstat(2) to set "assume unchanged" bits for paths that match index.
Junio C Hamanof9666ad2006-02-12 01:48:47 -0800386<2> mark the path to be edited.
387<3> this does lstat(2) and finds index matches the path.
Sean Estabrooks48aeecd2006-04-28 09:15:05 -0400388<4> this does lstat(2) and finds index does *not* match the path.
Junio C Hamanof9666ad2006-02-12 01:48:47 -0800389<5> registering the new version to index sets "assume unchanged" bit.
390<6> and it is assumed unchanged.
391<7> even after you edit it.
392<8> you can tell about the change after the fact.
393<9> now it checks with lstat(2) and finds it has been changed.
Junio C Hamanof9666ad2006-02-12 01:48:47 -0800394
David Greaves2cf565c2005-05-10 22:32:30 +0100395
Nguyễn Thái Ngọc Duy76a87882018-04-30 17:35:33 +0200396SKIP-WORKTREE BIT
Nguyễn Thái Ngọc Duy44a36912009-08-20 20:46:57 +0700397-----------------
398
Elijah Newren90235352022-01-14 15:59:42 +0000399Skip-worktree bit can be defined in one (long) sentence: Tell git to
400avoid writing the file to the working directory when reasonably
401possible, and treat the file as unchanged when it is not
402present in the working directory.
Nguyễn Thái Ngọc Duy44a36912009-08-20 20:46:57 +0700403
Elijah Newren90235352022-01-14 15:59:42 +0000404Note that not all git commands will pay attention to this bit, and
405some only partially support it.
406
407The update-index flags and the read-tree capabilities relating to the
408skip-worktree bit predated the introduction of the
409linkgit:git-sparse-checkout[1] command, which provides a much easier
410way to configure and handle the skip-worktree bits. If you want to
411reduce your working tree to only deal with a subset of the files in
412the repository, we strongly encourage the use of
413linkgit:git-sparse-checkout[1] in preference to the low-level
414update-index and read-tree primitives.
415
416The primary purpose of the skip-worktree bit is to enable sparse
417checkouts, i.e. to have working directories with only a subset of
418paths present. When the skip-worktree bit is set, Git commands (such
419as `switch`, `pull`, `merge`) will avoid writing these files.
420However, these commands will sometimes write these files anyway in
421important cases such as conflicts during a merge or rebase. Git
422commands will also avoid treating the lack of such files as an
Jacob Stopakc9dba102022-09-11 03:23:20 -0700423intentional deletion; for example `git add -u` will not stage a
Elijah Newren90235352022-01-14 15:59:42 +0000424deletion for these files and `git commit -a` will not make a commit
425deleting them either.
Nguyễn Thái Ngọc Duy44a36912009-08-20 20:46:57 +0700426
427Although this bit looks similar to assume-unchanged bit, its goal is
Elijah Newren90235352022-01-14 15:59:42 +0000428different. The assume-unchanged bit is for leaving the file in the
429working tree but having Git omit checking it for changes and presuming
430that the file has not been changed (though if it can determine without
431stat'ing the file that it has changed, it is free to record the
432changes). skip-worktree tells Git to ignore the absence of the file,
433avoid updating it when possible with commands that normally update
434much of the working directory (e.g. `checkout`, `switch`, `pull`,
435etc.), and not have its absence be recorded in commits. Note that in
436sparse checkouts (setup by `git sparse-checkout` or by configuring
437core.sparseCheckout to true), if a file is marked as skip-worktree in
438the index but is found in the working tree, Git will clear the
439skip-worktree bit for that file.
Nguyễn Thái Ngọc Duy44a36912009-08-20 20:46:57 +0700440
Nguyễn Thái Ngọc Duy76a87882018-04-30 17:35:33 +0200441SPLIT INDEX
Christian Couderb4601392017-03-06 10:42:03 +0100442-----------
443
444This mode is designed for repositories with very large indexes, and
445aims at reducing the time it takes to repeatedly write these indexes.
446
447In this mode, the index is split into two files, $GIT_DIR/index and
448$GIT_DIR/sharedindex.<SHA-1>. Changes are accumulated in
449$GIT_DIR/index, the split index, while the shared index file contains
450all index entries and stays unchanged.
451
452All changes in the split index are pushed back to the shared index
453file when the number of entries in the split index reaches a level
454specified by the splitIndex.maxPercentChange config variable (see
455linkgit:git-config[1]).
456
457Each time a new shared index file is created, the old shared index
458files are deleted if their modification time is older than what is
459specified by the splitIndex.sharedIndexExpire config variable (see
460linkgit:git-config[1]).
461
462To avoid deleting a shared index file that is still used, its
Elijah Newren031fd4b2019-11-05 17:07:20 +0000463modification time is updated to the current time every time a new split
Christian Couderb4601392017-03-06 10:42:03 +0100464index based on the shared index file is either created or read from.
465
Nguyễn Thái Ngọc Duy76a87882018-04-30 17:35:33 +0200466UNTRACKED CACHE
Christian Couder435ec092016-01-27 07:58:05 +0100467---------------
468
469This cache is meant to speed up commands that involve determining
470untracked files such as `git status`.
471
472This feature works by recording the mtime of the working tree
473directories and then omitting reading directories and stat calls
474against files in those directories whose mtime hasn't changed. For
475this to work the underlying operating system and file system must
476change the `st_mtime` field of directories if files in the directory
477are added, modified or deleted.
478
479You can test whether the filesystem supports that with the
480`--test-untracked-cache` option. The `--untracked-cache` option used
481to implicitly perform that test in older versions of Git, but that's
482no longer the case.
483
484If you want to enable (or disable) this feature, it is easier to use
485the `core.untrackedCache` configuration variable (see
486linkgit:git-config[1]) than using the `--untracked-cache` option to
487`git update-index` in each repository, especially if you want to do so
488across all repositories you use, because you can set the configuration
489variable to `true` (or `false`) in your `$HOME/.gitconfig` just once
490and have it affect all repositories you touch.
491
492When the `core.untrackedCache` configuration variable is changed, the
493untracked cache is added to or removed from the index the next time a
494command reads the index; while when `--[no-|force-]untracked-cache`
495are used, the untracked cache is immediately added to or removed from
496the index.
Nguyễn Thái Ngọc Duy44a36912009-08-20 20:46:57 +0700497
Ævar Arnfjörð Bjarmason9b978692018-02-09 21:04:30 +0000498Before 2.17, the untracked cache had a bug where replacing a directory
499with a symlink to another directory could cause it to incorrectly show
500files tracked by git as untracked. See the "status: add a failing test
501showing a core.untrackedCache bug" commit to git.git. A workaround for
502that is (and this might work for other undiscovered bugs in the
503future):
504
505----------------
506$ git -c core.untrackedCache=false status
507----------------
508
509This bug has also been shown to affect non-symlink cases of replacing
510a directory with a file when it comes to the internal structures of
511the untracked cache, but no case has been reported where this resulted in
512wrong "git status" output.
513
Ævar Arnfjörð Bjarmason7bf0be72018-02-09 21:04:31 +0000514There are also cases where existing indexes written by git versions
515before 2.17 will reference directories that don't exist anymore,
516potentially causing many "could not open directory" warnings to be
517printed on "git status". These are new warnings for existing issues
518that were previously silently discarded.
519
520As with the bug described above the solution is to one-off do a "git
521status" run with `core.untrackedCache=false` to flush out the leftover
522bad data.
523
Nguyễn Thái Ngọc Duy76a87882018-04-30 17:35:33 +0200524FILE SYSTEM MONITOR
Ben Peart780494b2017-09-22 12:35:41 -0400525-------------------
526
527This feature is intended to speed up git operations for repos that have
528large working directories.
529
Jeff Hostetler32484862022-03-25 18:02:48 +0000530It enables git to work together with a file system monitor (see
Todd Zullingerf3ea4be2022-04-06 14:41:22 -0400531linkgit:git-fsmonitor{litdd}daemon[1]
Jeff Hostetler32484862022-03-25 18:02:48 +0000532and the
Ben Peart780494b2017-09-22 12:35:41 -0400533"fsmonitor-watchman" section of linkgit:githooks[5]) that can
534inform it as to what files have been modified. This enables git to avoid
535having to lstat() every file to find modified files.
536
537When used in conjunction with the untracked cache, it can further improve
538performance by avoiding the cost of scanning the entire working directory
539looking for new files.
540
541If you want to enable (or disable) this feature, it is easier to use
542the `core.fsmonitor` configuration variable (see
Jeff Hostetler32484862022-03-25 18:02:48 +0000543linkgit:git-config[1]) than using the `--fsmonitor` option to `git
544update-index` in each repository, especially if you want to do so
Ben Peart780494b2017-09-22 12:35:41 -0400545across all repositories you use, because you can set the configuration
Ben Peart4ccf4612018-02-14 10:41:30 -0500546variable in your `$HOME/.gitconfig` just once and have it affect all
547repositories you touch.
Ben Peart780494b2017-09-22 12:35:41 -0400548
549When the `core.fsmonitor` configuration variable is changed, the
550file system monitor is added to or removed from the index the next time
551a command reads the index. When `--[no-]fsmonitor` are used, the file
552system monitor is immediately added to or removed from the index.
553
Nguyễn Thái Ngọc Duy76a87882018-04-30 17:35:33 +0200554CONFIGURATION
Junio C Hamano5773c9f2005-10-29 14:32:56 -0700555-------------
556
557The command honors `core.filemode` configuration variable. If
Štěpán Němec466d1f12009-11-10 19:11:51 +0100558your repository is on a filesystem whose executable bits are
Dan McGee5162e692007-12-29 00:20:38 -0600559unreliable, this should be set to 'false' (see linkgit:git-config[1]).
Jon Loeliger61f693b2005-12-05 23:13:03 -0600560This causes the command to ignore differences in file modes recorded
561in the index and the file mode on the filesystem if they differ only on
Junio C Hamano5773c9f2005-10-29 14:32:56 -0700562executable bit. On such an unfortunate filesystem, you may
Thomas Rast0b444cd2010-01-10 00:33:00 +0100563need to use 'git update-index --chmod='.
Junio C Hamano5773c9f2005-10-29 14:32:56 -0700564
Johannes Sixt78a8d642007-03-02 22:11:30 +0100565Quite similarly, if `core.symlinks` configuration variable is set
Dan McGee5162e692007-12-29 00:20:38 -0600566to 'false' (see linkgit:git-config[1]), symbolic links are checked out
Johannes Sixt78a8d642007-03-02 22:11:30 +0100567as plain files, and this command does not modify a recorded file mode
568from symbolic link to regular file.
569
Junio C Hamanof9666ad2006-02-12 01:48:47 -0800570The command looks at `core.ignorestat` configuration variable. See
571'Using "assume unchanged" bit' section above.
572
Alex Riesen1ce47902008-07-28 08:31:28 +0200573The command also looks at `core.trustctime` configuration variable.
574It can be useful when the inode change time is regularly modified by
575something outside Git (file system crawlers and backup systems use
576ctime for marking files processed) (see linkgit:git-config[1]).
577
Christian Couder435ec092016-01-27 07:58:05 +0100578The untracked cache extension can be enabled by the
579`core.untrackedCache` configuration variable (see
580linkgit:git-config[1]).
Jon Loeliger61f693b2005-12-05 23:13:03 -0600581
brian m. carlson1b13e902020-01-22 03:45:42 +0000582NOTES
583-----
584
585Users often try to use the assume-unchanged and skip-worktree bits
586to tell Git to ignore changes to files that are tracked. This does not
587work as expected, since Git may still check working tree files against
588the index when performing certain operations. In general, Git does not
589provide a way to ignore changes to tracked files, so alternate solutions
590are recommended.
591
592For example, if the file you want to change is some sort of config file,
593the repository can include a sample config file that can then be copied
594into the ignored name and modified. The repository can even include a
595script to treat the sample file as a template, modifying and copying it
596automatically.
597
Junio C Hamano56ae8df2008-05-28 16:55:27 -0700598SEE ALSO
Jon Loeliger61f693b2005-12-05 23:13:03 -0600599--------
Dan McGee5162e692007-12-29 00:20:38 -0600600linkgit:git-config[1],
Stefan Naeweacd6d7e2011-09-21 08:21:50 +0200601linkgit:git-add[1],
602linkgit:git-ls-files[1]
Jon Loeliger61f693b2005-12-05 23:13:03 -0600603
David Greaves2cf565c2005-05-10 22:32:30 +0100604GIT
605---
Christian Couder9e1f0a82008-06-06 09:07:32 +0200606Part of the linkgit:git[1] suite