3 ms·
The index is just a list of the files and associated metadata, it is not their contents. So git grep still needs to read the files from disk, though it doesn't
by js2 15y ago
The index is just a list of the files and associated metadata, it is not their contents. So git grep still needs to read the files from disk, though it doesn't need to walk the filesystem to locate them[@].
[@] Technically git grep has five modes of operation:
1. Search the contents of the tracked files as they currently are on disk. This is the default.
2. With --cached, search the contents of the tracked files as they are in the index (i.e. ignore any un-added changes).
3. With --no-index, search all files recursively from the current directory down. This allows you to use "git grep" as a "grep -R" replacement even when your CWD is not inside a repo.
4. With --untracked, search all files recursively from the current directory down in addition to files in the index. (The difference between this and --no-index when used inside a repo is that --untracked honors the .gitignore mechanism by default, i.e., --untracked is a synonym for --no-index --exclude-standard when inside a repo.)
5. With a tree'ish (commit, tag, branch name, etc), search all files in the tree.