Register file contents in the working tree to the index.
The git update-index command is a plumbing command used to manipulate the index (staging area) directly. While git add is the user-facing command for staging changes, update-index provides fine-grained control over index entries.
This command can modify the index in ways that git add cannot, such as marking files as assume-unchanged to temporarily ignore modifications, or adding file entries with specific modes and SHA values.
update-index is commonly used in scripts and hooks, and the --assume-unchanged flag is particularly popular for temporarily ignoring changes to tracked configuration files during development.
| Name | Description | Optional |
|---|---|---|
--add |
If a specified file is not in the index already, it is added. | Yes |
--remove |
If a specified file is in the index but missing from the working tree, it is removed. | Yes |
--assume-unchanged |
Set the assume-unchanged bit for the specified files. | Yes |
--no-assume-unchanged |
Unset the assume-unchanged bit for the specified files. | Yes |
git update-index --assume-unchanged config/local.yml
git update-index --no-assume-unchanged config/local.yml
git update-index --add new-file.txt
git ls-files -v | grep '^h'