Tracked, ignored, untracked — slice it however.
git ls-files prints files Git knows about, sliced by state: cached, modified, deleted, untracked, ignored, unmerged. The Swiss army knife for scripting against the index.
It is a query against the index (and optionally the working tree and exclude rules). Each flag toggles a category; combine with --exclude-standard to honor .gitignore.
git ls-files [-c|-d|-m|-o|-i|-s|-u] [--exclude-standard] [--with-tree=<tree>] [-z] [<path>...]| Flag | What it does |
|---|---|
-c, --cached | Show files in the index (the default) |
-d, --deleted | Show files deleted from the working tree but still in the index |
-m, --modified | Show files modified in the working tree vs the index |
-o, --others | Show untracked files (combine with --exclude-standard) |
-i, --ignored | Show ignored files (requires an exclude flag like --exclude-standard) |
-s, --stage | Show <mode> <sha> <stage>\t<path> — gold for scripting |
-u, --unmerged | Show files with merge conflicts (stage > 0) |
--exclude-standard | Apply .gitignore, .git/info/exclude, and core.excludesFile |
--with-tree=<tree> | Pretend the index matches <tree> for the query |
-z | NUL-terminate output for safe piping into xargs -0 |
git ls-filesgit ls-files -o --exclude-standardgit ls-files -sgit ls-files -z | xargs -0 wc -lHit each option, then Check answers. Score is recorded; Next is always open.