LinuxCommandLibrary

git-update-index

Manage files in the Git index

TLDR

Pretend that a modified file is unchanged (git status will not show this as changed)

$ git update-index --skip-worktree [path/to/modified_file]
copy

SYNOPSIS

git update-index [-q] [--unmerged] [--ignore-missing] [--chmod ] [--[no-]assume-unchanged] [--[no-]skip-worktree] [--[no-]fsmonitor-valid] [--[no-]cacheinfo [,,]] [--add] [--remove] [--replace] [--refresh] [-g] [-z] [--index-info] [--force-remove] [--really-refresh] [--unresolve] [--split-index] [--no-split-index] [--[no-]resolve-undo] [--test-resolve-undo] [--verbose] [--] [...]

PARAMETERS

-q
    Be quiet.

--unmerged
    Show unmerged index entries.

--ignore-missing
    Ignore missing files instead of erroring.

--chmod
    Change the executable bits of the index entries.

--[no-]assume-unchanged
    Mark/unmark files as assumed unchanged. This can speed up status operations if you are certain files are not being modified.

--[no-]skip-worktree
    Mark/unmark files as skip-worktree. Useful for excluding files from certain operations (e.g., checkout) without removing them from the repository.

--[no-]fsmonitor-valid
    Marks the fsmonitor as valid or invalid for the given paths.

--[no-]cacheinfo [,,]
    Add, update or delete a file directly from the object database, bypassing the working directory.

--add
    Add the specified file(s) to the index.

--remove
    Remove the specified file(s) from the index.

--replace
    Replace the specified file(s) in the index.

--refresh
    Refresh the index by checking the working directory. Useful after external modifications.

-g
    Perform a garbage collection of unreachables.

-z
    Use NUL as separator for index-info input.

--index-info
    Read index information from standard input.

--force-remove
    Remove even if the file is not in the index.

--really-refresh
    Like --refresh, but do not only check at the end.

--unresolve
    Resets files to their state prior to a merge.

--split-index
    Enable split index mode.

--no-split-index
    Disable split index mode.

--[no-]resolve-undo
    Record / restore information about unmerged file to resolve-undo data.

--test-resolve-undo
    Test whether resolve-undo data is usable.

--verbose
    Be verbose.

[...]
    The file(s) to operate on.

DESCRIPTION

The git update-index command is a powerful tool for managing the Git index (staging area). It allows you to add, modify, or remove entries from the index, affecting how Git views your working directory changes. It is primarily used to control what gets included in the next commit. Common use cases include:
- Adding new files to be tracked.
- Marking files as assumed-unchanged to speed up status checks.
- Ignoring changes to specific files in the working tree.
The index is a crucial component of Git's architecture, acting as a staging area where changes are prepared before being committed to the repository's history. Understanding and utilizing git update-index effectively is essential for precise control over the commit process.

CAVEATS

Using --assume-unchanged can be risky, as Git will not detect changes made to these files. Be cautious and regularly check the status of your repository.

ASSUME-UNCHANGED VS. SKIP-WORKTREE

Both --assume-unchanged and --skip-worktree can be used to ignore changes in the working directory. The key difference is that --assume-unchanged is a local optimization, and Git may still check the file if it suspects a change. --skip-worktree, on the other hand, is intended for files that should never be touched by Git in the working directory. This makes --skip-worktree the better choice for configuration files that are customized on each machine but should not be tracked in the repository.

INDEX MANIPULATION

The index is a binary file located in the .git/index directory. Directly manipulating the index file is strongly discouraged. Always use git update-index or other Git commands to modify the index.

SEE ALSO

Copied to clipboard