Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 1 | git-update-index(1) |
| 2 | =================== |
| 3 | |
| 4 | NAME |
| 5 | ---- |
Junio C Hamano | 7c73c66 | 2007-01-19 00:37:50 | [diff] [blame] | 6 | git-update-index - Register file contents in the working tree to the index |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 7 | |
| 8 | |
| 9 | SYNOPSIS |
| 10 | -------- |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 11 | [verse] |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 12 | 'git update-index' |
Junio C Hamano | 46338f5 | 2006-05-04 00:46:44 | [diff] [blame] | 13 | [--add] [--remove | --force-remove] [--replace] |
| 14 | [--refresh] [-q] [--unmerged] [--ignore-missing] |
Junio C Hamano | d75148a | 2014-04-08 19:48:38 | [diff] [blame] | 15 | [(--cacheinfo <mode>,<object>,<file>)...] |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 16 | [--chmod=(+|-)x] |
Junio C Hamano | 3d1b5a1 | 2013-05-17 23:34:02 | [diff] [blame] | 17 | [--[no-]assume-unchanged] |
| 18 | [--[no-]skip-worktree] |
Junio C Hamano | 8ac8a3d | 2019-11-11 04:33:46 | [diff] [blame] | 19 | [--[no-]ignore-skip-worktree-entries] |
Junio C Hamano | d710560 | 2017-11-21 05:32:50 | [diff] [blame] | 20 | [--[no-]fsmonitor-valid] |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 21 | [--ignore-submodules] |
Junio C Hamano | d30e7ef | 2015-12-10 22:27:17 | [diff] [blame] | 22 | [--[no-]split-index] |
Junio C Hamano | 9099a7c | 2016-02-10 23:42:05 | [diff] [blame] | 23 | [--[no-|test-|force-]untracked-cache] |
Junio C Hamano | d710560 | 2017-11-21 05:32:50 | [diff] [blame] | 24 | [--[no-]fsmonitor] |
Junio C Hamano | 8a0a21e | 2006-08-24 07:37:45 | [diff] [blame] | 25 | [--really-refresh] [--unresolve] [--again | -g] |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 26 | [--info-only] [--index-info] |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 27 | [-z] [--stdin] [--index-version <n>] |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 28 | [--verbose] |
Junio C Hamano | d2179ef | 2010-10-22 04:12:17 | [diff] [blame] | 29 | [--] [<file>...] |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 30 | |
| 31 | DESCRIPTION |
| 32 | ----------- |
Junio C Hamano | 7887f9b | 2021-01-25 23:32:33 | [diff] [blame] | 33 | Modifies the index. Each file mentioned is updated into the index and |
| 34 | any 'unmerged' or 'needs updating' state is cleared. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 35 | |
Junio C Hamano | 35738e8 | 2008-01-07 07:55:46 | [diff] [blame] | 36 | See also linkgit:git-add[1] for a more user-friendly way to do some of |
Junio C Hamano | 3d30fd5 | 2007-05-08 00:32:53 | [diff] [blame] | 37 | the most common operations on the index. |
| 38 | |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 39 | The way 'git update-index' handles files it is told about can be modified |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 40 | using the various options: |
| 41 | |
| 42 | OPTIONS |
| 43 | ------- |
| 44 | --add:: |
| 45 | If a specified file isn't in the index already then it's |
| 46 | added. |
| 47 | Default behaviour is to ignore new files. |
| 48 | |
| 49 | --remove:: |
| 50 | If a specified file is in the index but is missing then it's |
| 51 | removed. |
Junio C Hamano | 341071d | 2006-06-04 07:24:48 | [diff] [blame] | 52 | Default behavior is to ignore removed file. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 53 | |
| 54 | --refresh:: |
| 55 | Looks at the current index and checks to see if merges or |
| 56 | updates are needed by checking stat() information. |
| 57 | |
| 58 | -q:: |
| 59 | Quiet. If --refresh finds that the index needs an update, the |
| 60 | default behavior is to error out. This option makes |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 61 | 'git update-index' continue anyway. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 62 | |
Junio C Hamano | 54bf1e2 | 2008-12-20 06:30:11 | [diff] [blame] | 63 | --ignore-submodules:: |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 64 | Do not try to update submodules. This option is only respected |
| 65 | when passed before --refresh. |
| 66 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 67 | --unmerged:: |
| 68 | If --refresh finds unmerged changes in the index, the default |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 69 | behavior is to error out. This option makes 'git update-index' |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 70 | continue anyway. |
| 71 | |
| 72 | --ignore-missing:: |
| 73 | Ignores missing files during a --refresh |
| 74 | |
Junio C Hamano | d75148a | 2014-04-08 19:48:38 | [diff] [blame] | 75 | --cacheinfo <mode>,<object>,<path>:: |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 76 | --cacheinfo <mode> <object> <path>:: |
Junio C Hamano | d75148a | 2014-04-08 19:48:38 | [diff] [blame] | 77 | 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 Hamano | a77a513 | 2007-06-08 16:13:44 | [diff] [blame] | 81 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 82 | --index-info:: |
| 83 | Read index information from stdin. |
| 84 | |
| 85 | --chmod=(+|-)x:: |
Junio C Hamano | a77a513 | 2007-06-08 16:13:44 | [diff] [blame] | 86 | Set the execute permissions on the updated files. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 87 | |
Junio C Hamano | 3d1b5a1 | 2013-05-17 23:34:02 | [diff] [blame] | 88 | --[no-]assume-unchanged:: |
Junio C Hamano | 6df93d9 | 2014-12-22 22:48:09 | [diff] [blame] | 89 | 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 Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 97 | sometimes helpful when working with a big project on a |
| 98 | filesystem that has very slow lstat(2) system call |
| 99 | (e.g. cifs). |
Junio C Hamano | 915cd9b | 2008-07-20 01:24:17 | [diff] [blame] | 100 | + |
Junio C Hamano | 915cd9b | 2008-07-20 01:24:17 | [diff] [blame] | 101 | Git will fail (gracefully) in case it needs to modify this file |
| 102 | in the index e.g. when merging in a commit; |
| 103 | thus, in case the assumed-untracked file is changed upstream, |
| 104 | you will need to handle the situation manually. |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 105 | |
Junio C Hamano | 446ed77 | 2009-11-10 22:02:20 | [diff] [blame] | 106 | --really-refresh:: |
Junio C Hamano | 92d8037 | 2016-07-13 22:00:05 | [diff] [blame] | 107 | Like `--refresh`, but checks stat information unconditionally, |
Junio C Hamano | 446ed77 | 2009-11-10 22:02:20 | [diff] [blame] | 108 | without regard to the "assume unchanged" setting. |
| 109 | |
Junio C Hamano | 3d1b5a1 | 2013-05-17 23:34:02 | [diff] [blame] | 110 | --[no-]skip-worktree:: |
Junio C Hamano | 3c8d670 | 2010-01-13 23:09:03 | [diff] [blame] | 111 | 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 | |
Junio C Hamano | 8ac8a3d | 2019-11-11 04:33:46 | [diff] [blame] | 116 | |
| 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 | |
Junio C Hamano | d710560 | 2017-11-21 05:32:50 | [diff] [blame] | 121 | --[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 | |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 127 | -g:: |
| 128 | --again:: |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 129 | Runs 'git update-index' itself on the paths whose index |
Junio C Hamano | 26a5737 | 2006-05-10 00:13:40 | [diff] [blame] | 130 | entries are different from those from the `HEAD` commit. |
| 131 | |
Junio C Hamano | 46338f5 | 2006-05-04 00:46:44 | [diff] [blame] | 132 | --unresolve:: |
| 133 | Restores the 'unmerged' or 'needs updating' state of a |
| 134 | file during a merge if it was cleared by accident. |
| 135 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 136 | --info-only:: |
| 137 | Do not create objects in the object database for all |
| 138 | <file> arguments that follow this flag; just insert |
| 139 | their object IDs into the index. |
| 140 | |
| 141 | --force-remove:: |
| 142 | Remove the file from the index even when the working directory |
| 143 | still has such a file. (Implies --remove.) |
| 144 | |
| 145 | --replace:: |
| 146 | By default, when a file `path` exists in the index, |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 147 | 'git update-index' refuses an attempt to add `path/file`. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 148 | Similarly if a file `path/file` exists, a file `path` |
| 149 | cannot be added. With --replace flag, existing entries |
Junio C Hamano | 54bf1e2 | 2008-12-20 06:30:11 | [diff] [blame] | 150 | that conflict with the entry being added are |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 151 | automatically removed with warning messages. |
| 152 | |
| 153 | --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 | |
| 158 | --verbose:: |
| 159 | Report what is being added and removed from index. |
| 160 | |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 161 | --index-version <n>:: |
| 162 | Write the resulting index out in the named on-disk format version. |
Junio C Hamano | 947ab82 | 2013-03-19 23:07:29 | [diff] [blame] | 163 | 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 | + |
| 167 | Version 4 performs a simple pathname compression that reduces index |
| 168 | size by 30%-50% on large repositories, which results in faster load |
Junio C Hamano | d4bbec0 | 2017-09-25 07:24:53 | [diff] [blame] | 169 | time. Version 4 is relatively young (first released in 1.8.0 in |
Junio C Hamano | 947ab82 | 2013-03-19 23:07:29 | [diff] [blame] | 170 | October 2012). Other Git implementations such as JGit and libgit2 |
| 171 | may not support it yet. |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 172 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 173 | -z:: |
Junio C Hamano | c27b733 | 2010-10-14 04:37:28 | [diff] [blame] | 174 | Only meaningful with `--stdin` or `--index-info`; paths are |
| 175 | separated with NUL character instead of LF. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 176 | |
Junio C Hamano | 6f0c944 | 2014-07-16 21:51:32 | [diff] [blame] | 177 | --split-index:: |
| 178 | --no-split-index:: |
Junio C Hamano | 3d4a66d | 2017-03-17 21:07:26 | [diff] [blame] | 179 | 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. |
| 183 | + |
| 184 | These options take effect whatever the value of the `core.splitIndex` |
| 185 | configuration variable (see linkgit:git-config[1]). But a warning is |
| 186 | emitted when the change goes against the configured value, as the |
| 187 | configured value will take effect next time the index is read and this |
| 188 | will remove the intended effect of the option. |
Junio C Hamano | 6f0c944 | 2014-07-16 21:51:32 | [diff] [blame] | 189 | |
Junio C Hamano | c4e2a20 | 2015-05-26 21:38:47 | [diff] [blame] | 190 | --untracked-cache:: |
| 191 | --no-untracked-cache:: |
Junio C Hamano | 9099a7c | 2016-02-10 23:42:05 | [diff] [blame] | 192 | Enable or disable untracked cache feature. Please use |
| 193 | `--test-untracked-cache` before enabling it. |
| 194 | + |
| 195 | These options take effect whatever the value of the `core.untrackedCache` |
| 196 | configuration variable (see linkgit:git-config[1]). But a warning is |
| 197 | emitted when the change goes against the configured value, as the |
| 198 | configured value will take effect next time the index is read and this |
| 199 | will remove the intended effect of the option. |
| 200 | |
| 201 | --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 |
| 204 | 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. |
Junio C Hamano | c4e2a20 | 2015-05-26 21:38:47 | [diff] [blame] | 210 | |
| 211 | --force-untracked-cache:: |
Junio C Hamano | 9099a7c | 2016-02-10 23:42:05 | [diff] [blame] | 212 | 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. |
Junio C Hamano | c4e2a20 | 2015-05-26 21:38:47 | [diff] [blame] | 216 | |
Junio C Hamano | d710560 | 2017-11-21 05:32:50 | [diff] [blame] | 217 | --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 | |
Junio C Hamano | 1bb569e | 2006-05-05 23:14:25 | [diff] [blame] | 226 | \--:: |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 227 | Do not interpret any more arguments as options. |
| 228 | |
| 229 | <file>:: |
| 230 | Files to act on. |
| 231 | Note that files beginning with '.' are discarded. This includes |
Junio C Hamano | a77a513 | 2007-06-08 16:13:44 | [diff] [blame] | 232 | `./file` and `dir/./file`. If you don't want this, then use |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 233 | cleaner names. |
| 234 | The same applies to directories ending '/' and paths with '//' |
| 235 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 236 | USING --REFRESH |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 237 | --------------- |
Junio C Hamano | 92d8037 | 2016-07-13 22:00:05 | [diff] [blame] | 238 | `--refresh` does not calculate a new sha1 file or bring the index |
Junio C Hamano | 88bf571 | 2017-09-10 08:39:23 | [diff] [blame] | 239 | up to date for mode/content changes. But what it *does* do is to |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 240 | "re-match" the stat information of a file with the index, so that you |
| 241 | can refresh the index for a file that hasn't been changed but where |
| 242 | the stat entry is out of date. |
| 243 | |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 244 | For example, you'd want to do this after doing a 'git read-tree', to link |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 245 | up the stat index details with the proper files. |
| 246 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 247 | USING --CACHEINFO OR --INFO-ONLY |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 248 | -------------------------------- |
Junio C Hamano | 92d8037 | 2016-07-13 22:00:05 | [diff] [blame] | 249 | `--cacheinfo` is used to register a file that is not in the |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 250 | current working directory. This is useful for minimum-checkout |
| 251 | merging. |
| 252 | |
Junio C Hamano | 11ae320 | 2018-08-20 20:15:42 | [diff] [blame] | 253 | To pretend you have a file at path with mode and sha1, say: |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 254 | |
| 255 | ---------------- |
Junio C Hamano | 11ae320 | 2018-08-20 20:15:42 | [diff] [blame] | 256 | $ git update-index --add --cacheinfo <mode>,<sha1>,<path> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 257 | ---------------- |
| 258 | |
Junio C Hamano | 92d8037 | 2016-07-13 22:00:05 | [diff] [blame] | 259 | `--info-only` is used to register files without placing them in the object |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 260 | database. This is useful for status-only repositories. |
| 261 | |
Junio C Hamano | 92d8037 | 2016-07-13 22:00:05 | [diff] [blame] | 262 | Both `--cacheinfo` and `--info-only` behave similarly: the index is updated |
| 263 | but the object database isn't. `--cacheinfo` is useful when the object is |
| 264 | in the database but the file isn't available locally. `--info-only` is |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 265 | useful when the file is available, but you do not wish to update the |
| 266 | object database. |
| 267 | |
| 268 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 269 | USING --INDEX-INFO |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 270 | ------------------ |
| 271 | |
| 272 | `--index-info` is a more powerful mechanism that lets you feed |
| 273 | multiple entry definitions from the standard input, and designed |
| 274 | specifically for scripts. It can take inputs of three formats: |
| 275 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 276 | . mode SP type SP sha1 TAB path |
| 277 | + |
Junio C Hamano | 11ae320 | 2018-08-20 20:15:42 | [diff] [blame] | 278 | This format is to stuff `git ls-tree` output into the index. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 279 | |
| 280 | . mode SP sha1 SP stage TAB path |
| 281 | + |
| 282 | This format is to put higher order stages into the |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 283 | index file and matches 'git ls-files --stage' output. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 284 | |
Junio C Hamano | 11ae320 | 2018-08-20 20:15:42 | [diff] [blame] | 285 | . mode SP sha1 TAB path |
| 286 | + |
| 287 | This format is no longer produced by any Git command, but is |
| 288 | and will continue to be supported by `update-index --index-info`. |
| 289 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 290 | To place a higher stage entry to the index, the path should |
| 291 | first be removed by feeding a mode=0 entry for the path, and |
| 292 | then feeding necessary input lines in the third format. |
| 293 | |
| 294 | For example, starting with this index: |
| 295 | |
| 296 | ------------ |
| 297 | $ git ls-files -s |
| 298 | 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 0 frotz |
| 299 | ------------ |
| 300 | |
| 301 | you can feed the following input to `--index-info`: |
| 302 | |
| 303 | ------------ |
| 304 | $ git update-index --index-info |
| 305 | 0 0000000000000000000000000000000000000000 frotz |
| 306 | 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz |
| 307 | 100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz |
| 308 | ------------ |
| 309 | |
| 310 | The first line of the input feeds 0 as the mode to remove the |
Junio C Hamano | e3f080d | 2013-04-22 02:27:13 | [diff] [blame] | 311 | path; the SHA-1 does not matter as long as it is well formatted. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 312 | Then the second and third line feeds stage 1 and stage 2 entries |
| 313 | for that path. After the above, we would end up with this: |
| 314 | |
| 315 | ------------ |
| 316 | $ git ls-files -s |
| 317 | 100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz |
| 318 | 100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz |
| 319 | ------------ |
| 320 | |
| 321 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 322 | USING ``ASSUME UNCHANGED'' BIT |
Junio C Hamano | fb2ead3 | 2006-11-13 23:40:59 | [diff] [blame] | 323 | ------------------------------ |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 324 | |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 325 | Many operations in Git depend on your filesystem to have an |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 326 | efficient `lstat(2)` implementation, so that `st_mtime` |
| 327 | information for working tree files can be cheaply checked to see |
| 328 | if the file contents have changed from the version recorded in |
| 329 | the index file. Unfortunately, some filesystems have |
| 330 | inefficient `lstat(2)`. If your filesystem is one of them, you |
| 331 | can set "assume unchanged" bit to paths you have not changed to |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 332 | cause Git not to do this check. Note that setting this bit on a |
| 333 | path does not mean Git will check the contents of the file to |
| 334 | see if it has changed -- it makes Git to omit any checking and |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 335 | assume it has *not* changed. When you make changes to working |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 336 | tree files, you have to explicitly tell Git about it by dropping |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 337 | "assume unchanged" bit, either before or after you modify them. |
| 338 | |
| 339 | In order to set "assume unchanged" bit, use `--assume-unchanged` |
Junio C Hamano | 8fb66e5 | 2011-10-05 20:59:51 | [diff] [blame] | 340 | option. To unset, use `--no-assume-unchanged`. To see which files |
| 341 | have the "assume unchanged" bit set, use `git ls-files -v` |
| 342 | (see linkgit:git-ls-files[1]). |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 343 | |
| 344 | The command looks at `core.ignorestat` configuration variable. When |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 345 | this is true, paths updated with `git update-index paths...` and |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 346 | paths updated with other Git commands that update both index and |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 347 | working tree (e.g. 'git apply --index', 'git checkout-index -u', |
| 348 | and 'git read-tree -u') are automatically marked as "assume |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 349 | unchanged". Note that "assume unchanged" bit is *not* set if |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 350 | `git update-index --refresh` finds the working tree file matches |
| 351 | the index (use `git update-index --really-refresh` if you want |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 352 | to mark them as "assume unchanged"). |
| 353 | |
Junio C Hamano | 7c37da7 | 2022-03-09 22:19:31 | [diff] [blame] | 354 | Sometimes users confuse the assume-unchanged bit with the |
| 355 | skip-worktree bit. See the final paragraph in the "Skip-worktree bit" |
| 356 | section below for an explanation of the differences. |
| 357 | |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 358 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 359 | EXAMPLES |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 360 | -------- |
| 361 | To update and refresh only the files already checked out: |
| 362 | |
| 363 | ---------------- |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 364 | $ git checkout-index -n -f -a && git update-index --ignore-missing --refresh |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 365 | ---------------- |
| 366 | |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 367 | On an inefficient filesystem with `core.ignorestat` set:: |
| 368 | + |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 369 | ------------ |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 370 | $ git update-index --really-refresh <1> |
| 371 | $ git update-index --no-assume-unchanged foo.c <2> |
| 372 | $ git diff --name-only <3> |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 373 | $ edit foo.c |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 374 | $ git diff --name-only <4> |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 375 | M foo.c |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 376 | $ git update-index foo.c <5> |
| 377 | $ git diff --name-only <6> |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 378 | $ edit foo.c |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 379 | $ git diff --name-only <7> |
| 380 | $ git update-index --no-assume-unchanged foo.c <8> |
| 381 | $ git diff --name-only <9> |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 382 | M foo.c |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 383 | ------------ |
| 384 | + |
| 385 | <1> forces lstat(2) to set "assume unchanged" bits for paths that match index. |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 386 | <2> mark the path to be edited. |
| 387 | <3> this does lstat(2) and finds index matches the path. |
Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 388 | <4> this does lstat(2) and finds index does *not* match the path. |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 389 | <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 Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 394 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 395 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 396 | SKIP-WORKTREE BIT |
Junio C Hamano | 3c8d670 | 2010-01-13 23:09:03 | [diff] [blame] | 397 | ----------------- |
| 398 | |
Junio C Hamano | 7c37da7 | 2022-03-09 22:19:31 | [diff] [blame] | 399 | Skip-worktree bit can be defined in one (long) sentence: Tell git to |
| 400 | avoid writing the file to the working directory when reasonably |
| 401 | possible, and treat the file as unchanged when it is not |
| 402 | present in the working directory. |
Junio C Hamano | 3c8d670 | 2010-01-13 23:09:03 | [diff] [blame] | 403 | |
Junio C Hamano | 7c37da7 | 2022-03-09 22:19:31 | [diff] [blame] | 404 | Note that not all git commands will pay attention to this bit, and |
| 405 | some only partially support it. |
| 406 | |
| 407 | The update-index flags and the read-tree capabilities relating to the |
| 408 | skip-worktree bit predated the introduction of the |
| 409 | linkgit:git-sparse-checkout[1] command, which provides a much easier |
| 410 | way to configure and handle the skip-worktree bits. If you want to |
| 411 | reduce your working tree to only deal with a subset of the files in |
| 412 | the repository, we strongly encourage the use of |
| 413 | linkgit:git-sparse-checkout[1] in preference to the low-level |
| 414 | update-index and read-tree primitives. |
| 415 | |
| 416 | The primary purpose of the skip-worktree bit is to enable sparse |
| 417 | checkouts, i.e. to have working directories with only a subset of |
| 418 | paths present. When the skip-worktree bit is set, Git commands (such |
| 419 | as `switch`, `pull`, `merge`) will avoid writing these files. |
| 420 | However, these commands will sometimes write these files anyway in |
| 421 | important cases such as conflicts during a merge or rebase. Git |
| 422 | commands will also avoid treating the lack of such files as an |
Junio C Hamano | 3778ccc | 2022-09-15 23:33:17 | [diff] [blame] | 423 | intentional deletion; for example `git add -u` will not stage a |
Junio C Hamano | 7c37da7 | 2022-03-09 22:19:31 | [diff] [blame] | 424 | deletion for these files and `git commit -a` will not make a commit |
| 425 | deleting them either. |
Junio C Hamano | 3c8d670 | 2010-01-13 23:09:03 | [diff] [blame] | 426 | |
| 427 | Although this bit looks similar to assume-unchanged bit, its goal is |
Junio C Hamano | 7c37da7 | 2022-03-09 22:19:31 | [diff] [blame] | 428 | different. The assume-unchanged bit is for leaving the file in the |
| 429 | working tree but having Git omit checking it for changes and presuming |
| 430 | that the file has not been changed (though if it can determine without |
| 431 | stat'ing the file that it has changed, it is free to record the |
| 432 | changes). skip-worktree tells Git to ignore the absence of the file, |
| 433 | avoid updating it when possible with commands that normally update |
| 434 | much of the working directory (e.g. `checkout`, `switch`, `pull`, |
| 435 | etc.), and not have its absence be recorded in commits. Note that in |
| 436 | sparse checkouts (setup by `git sparse-checkout` or by configuring |
| 437 | core.sparseCheckout to true), if a file is marked as skip-worktree in |
| 438 | the index but is found in the working tree, Git will clear the |
| 439 | skip-worktree bit for that file. |
Junio C Hamano | 3c8d670 | 2010-01-13 23:09:03 | [diff] [blame] | 440 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 441 | SPLIT INDEX |
Junio C Hamano | 3d4a66d | 2017-03-17 21:07:26 | [diff] [blame] | 442 | ----------- |
| 443 | |
| 444 | This mode is designed for repositories with very large indexes, and |
| 445 | aims at reducing the time it takes to repeatedly write these indexes. |
| 446 | |
| 447 | In 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 |
| 450 | all index entries and stays unchanged. |
| 451 | |
| 452 | All changes in the split index are pushed back to the shared index |
| 453 | file when the number of entries in the split index reaches a level |
| 454 | specified by the splitIndex.maxPercentChange config variable (see |
| 455 | linkgit:git-config[1]). |
| 456 | |
| 457 | Each time a new shared index file is created, the old shared index |
| 458 | files are deleted if their modification time is older than what is |
| 459 | specified by the splitIndex.sharedIndexExpire config variable (see |
| 460 | linkgit:git-config[1]). |
| 461 | |
| 462 | To avoid deleting a shared index file that is still used, its |
Junio C Hamano | 8ef91f3 | 2019-12-01 22:58:27 | [diff] [blame] | 463 | modification time is updated to the current time every time a new split |
Junio C Hamano | 3d4a66d | 2017-03-17 21:07:26 | [diff] [blame] | 464 | index based on the shared index file is either created or read from. |
| 465 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 466 | UNTRACKED CACHE |
Junio C Hamano | 9099a7c | 2016-02-10 23:42:05 | [diff] [blame] | 467 | --------------- |
| 468 | |
| 469 | This cache is meant to speed up commands that involve determining |
| 470 | untracked files such as `git status`. |
| 471 | |
| 472 | This feature works by recording the mtime of the working tree |
| 473 | directories and then omitting reading directories and stat calls |
| 474 | against files in those directories whose mtime hasn't changed. For |
| 475 | this to work the underlying operating system and file system must |
| 476 | change the `st_mtime` field of directories if files in the directory |
| 477 | are added, modified or deleted. |
| 478 | |
| 479 | You can test whether the filesystem supports that with the |
| 480 | `--test-untracked-cache` option. The `--untracked-cache` option used |
| 481 | to implicitly perform that test in older versions of Git, but that's |
| 482 | no longer the case. |
| 483 | |
| 484 | If you want to enable (or disable) this feature, it is easier to use |
| 485 | the `core.untrackedCache` configuration variable (see |
| 486 | linkgit:git-config[1]) than using the `--untracked-cache` option to |
| 487 | `git update-index` in each repository, especially if you want to do so |
| 488 | across all repositories you use, because you can set the configuration |
| 489 | variable to `true` (or `false`) in your `$HOME/.gitconfig` just once |
| 490 | and have it affect all repositories you touch. |
| 491 | |
| 492 | When the `core.untrackedCache` configuration variable is changed, the |
| 493 | untracked cache is added to or removed from the index the next time a |
| 494 | command reads the index; while when `--[no-|force-]untracked-cache` |
| 495 | are used, the untracked cache is immediately added to or removed from |
| 496 | the index. |
Junio C Hamano | 3c8d670 | 2010-01-13 23:09:03 | [diff] [blame] | 497 | |
Junio C Hamano | 615c3b3 | 2018-02-28 23:40:27 | [diff] [blame] | 498 | Before 2.17, the untracked cache had a bug where replacing a directory |
| 499 | with a symlink to another directory could cause it to incorrectly show |
| 500 | files tracked by git as untracked. See the "status: add a failing test |
| 501 | showing a core.untrackedCache bug" commit to git.git. A workaround for |
| 502 | that is (and this might work for other undiscovered bugs in the |
| 503 | future): |
| 504 | |
| 505 | ---------------- |
| 506 | $ git -c core.untrackedCache=false status |
| 507 | ---------------- |
| 508 | |
| 509 | This bug has also been shown to affect non-symlink cases of replacing |
| 510 | a directory with a file when it comes to the internal structures of |
| 511 | the untracked cache, but no case has been reported where this resulted in |
| 512 | wrong "git status" output. |
| 513 | |
| 514 | There are also cases where existing indexes written by git versions |
| 515 | before 2.17 will reference directories that don't exist anymore, |
| 516 | potentially causing many "could not open directory" warnings to be |
| 517 | printed on "git status". These are new warnings for existing issues |
| 518 | that were previously silently discarded. |
| 519 | |
| 520 | As with the bug described above the solution is to one-off do a "git |
| 521 | status" run with `core.untrackedCache=false` to flush out the leftover |
| 522 | bad data. |
| 523 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 524 | FILE SYSTEM MONITOR |
Junio C Hamano | d710560 | 2017-11-21 05:32:50 | [diff] [blame] | 525 | ------------------- |
| 526 | |
| 527 | This feature is intended to speed up git operations for repos that have |
| 528 | large working directories. |
| 529 | |
Junio C Hamano | 4bea028 | 2022-04-04 18:21:49 | [diff] [blame] | 530 | It enables git to work together with a file system monitor (see |
Junio C Hamano | e80e7b5 | 2022-04-07 22:10:10 | [diff] [blame] | 531 | linkgit:git-fsmonitor{litdd}daemon[1] |
Junio C Hamano | 4bea028 | 2022-04-04 18:21:49 | [diff] [blame] | 532 | and the |
Junio C Hamano | d710560 | 2017-11-21 05:32:50 | [diff] [blame] | 533 | "fsmonitor-watchman" section of linkgit:githooks[5]) that can |
| 534 | inform it as to what files have been modified. This enables git to avoid |
| 535 | having to lstat() every file to find modified files. |
| 536 | |
| 537 | When used in conjunction with the untracked cache, it can further improve |
| 538 | performance by avoiding the cost of scanning the entire working directory |
| 539 | looking for new files. |
| 540 | |
| 541 | If you want to enable (or disable) this feature, it is easier to use |
| 542 | the `core.fsmonitor` configuration variable (see |
Junio C Hamano | 4bea028 | 2022-04-04 18:21:49 | [diff] [blame] | 543 | linkgit:git-config[1]) than using the `--fsmonitor` option to `git |
| 544 | update-index` in each repository, especially if you want to do so |
Junio C Hamano | d710560 | 2017-11-21 05:32:50 | [diff] [blame] | 545 | across all repositories you use, because you can set the configuration |
Junio C Hamano | 615c3b3 | 2018-02-28 23:40:27 | [diff] [blame] | 546 | variable in your `$HOME/.gitconfig` just once and have it affect all |
| 547 | repositories you touch. |
Junio C Hamano | d710560 | 2017-11-21 05:32:50 | [diff] [blame] | 548 | |
| 549 | When the `core.fsmonitor` configuration variable is changed, the |
| 550 | file system monitor is added to or removed from the index the next time |
| 551 | a command reads the index. When `--[no-]fsmonitor` are used, the file |
| 552 | system monitor is immediately added to or removed from the index. |
| 553 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 554 | CONFIGURATION |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 555 | ------------- |
| 556 | |
| 557 | The command honors `core.filemode` configuration variable. If |
Junio C Hamano | 446ed77 | 2009-11-10 22:02:20 | [diff] [blame] | 558 | your repository is on a filesystem whose executable bits are |
Junio C Hamano | 35738e8 | 2008-01-07 07:55:46 | [diff] [blame] | 559 | unreliable, this should be set to 'false' (see linkgit:git-config[1]). |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 560 | This causes the command to ignore differences in file modes recorded |
| 561 | in the index and the file mode on the filesystem if they differ only on |
| 562 | executable bit. On such an unfortunate filesystem, you may |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 563 | need to use 'git update-index --chmod='. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 564 | |
Junio C Hamano | aa83a7d | 2007-03-05 02:37:29 | [diff] [blame] | 565 | Quite similarly, if `core.symlinks` configuration variable is set |
Junio C Hamano | 35738e8 | 2008-01-07 07:55:46 | [diff] [blame] | 566 | to 'false' (see linkgit:git-config[1]), symbolic links are checked out |
Junio C Hamano | aa83a7d | 2007-03-05 02:37:29 | [diff] [blame] | 567 | as plain files, and this command does not modify a recorded file mode |
| 568 | from symbolic link to regular file. |
| 569 | |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 570 | The command looks at `core.ignorestat` configuration variable. See |
| 571 | 'Using "assume unchanged" bit' section above. |
| 572 | |
Junio C Hamano | 90ccff3 | 2008-07-29 08:17:24 | [diff] [blame] | 573 | The command also looks at `core.trustctime` configuration variable. |
| 574 | It can be useful when the inode change time is regularly modified by |
| 575 | something outside Git (file system crawlers and backup systems use |
| 576 | ctime for marking files processed) (see linkgit:git-config[1]). |
| 577 | |
Junio C Hamano | 9099a7c | 2016-02-10 23:42:05 | [diff] [blame] | 578 | The untracked cache extension can be enabled by the |
| 579 | `core.untrackedCache` configuration variable (see |
| 580 | linkgit:git-config[1]). |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 581 | |
Junio C Hamano | bee061d | 2020-01-30 23:21:18 | [diff] [blame] | 582 | NOTES |
| 583 | ----- |
| 584 | |
| 585 | Users often try to use the assume-unchanged and skip-worktree bits |
| 586 | to tell Git to ignore changes to files that are tracked. This does not |
| 587 | work as expected, since Git may still check working tree files against |
| 588 | the index when performing certain operations. In general, Git does not |
| 589 | provide a way to ignore changes to tracked files, so alternate solutions |
| 590 | are recommended. |
| 591 | |
| 592 | For example, if the file you want to change is some sort of config file, |
| 593 | the repository can include a sample config file that can then be copied |
| 594 | into the ignored name and modified. The repository can even include a |
| 595 | script to treat the sample file as a template, modifying and copying it |
| 596 | automatically. |
| 597 | |
Junio C Hamano | 9049d91 | 2008-05-29 02:09:50 | [diff] [blame] | 598 | SEE ALSO |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 599 | -------- |
Junio C Hamano | 35738e8 | 2008-01-07 07:55:46 | [diff] [blame] | 600 | linkgit:git-config[1], |
Junio C Hamano | 8fb66e5 | 2011-10-05 20:59:51 | [diff] [blame] | 601 | linkgit:git-add[1], |
| 602 | linkgit:git-ls-files[1] |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 603 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 604 | GIT |
| 605 | --- |
Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 606 | Part of the linkgit:git[1] suite |