Home·Terminal commands

git ls-files

git

Usage

git ls-files [-o|-m|-i] [--exclude-standard]

Lists paths from the index rather than from disk, which makes it the reliable list to script over; -i cannot stand alone and needs -c or -o plus --exclude-standard.

Common flags

FlagMeaning
-cfiles in the index; the default
-mtracked files modified on disk
-dtracked files that are missing
-ofiles git does not track
-iignored files; must come with -o or -c and --exclude-standard
--exclude-standardapply .gitignore and friends
-sshow mode and object id of each entry
-zseparate paths with NUL for xargs -0

Examples

git ls-files

every tracked path, straight from the index

git ls-files -o --exclude-standard

untracked files only, respecting .gitignore

git ls-files -i -c --exclude-standard

tracked files that .gitignore says should be ignored

The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does git ls-files do?

Lists paths from the index rather than from disk, which makes it the reliable list to script over; -i cannot stand alone and needs -c or -o plus --exclude-standard.

Q. How do I type it?

git ls-files [-o|-m|-i] [--exclude-standard] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

8 are listed here; the full set is in man git. This command sits under git.

Related commands

man page: man git-ls-files