Listing files in Git

Exploring git ls-files

This post describes, my experiments with git ls-files command.

In repository, we have files:

File structure in repository
1
2
3
4
5
6
7
.DS_Store (Mac OS X, folder settings file)
.git (Git repository file)
.gitignore (Git ignore file)
ignoredFile (Some file, that should be ignored)
inRepo (File in repository)
untracked (Som untracked file)
staged (Staged file)

This command show us, all committed files and staged files.

List files
1
2
3
4
$ git ls-files
.gitignore
inRepo
staged

This command show us, all files that are ignored or untracked. Those files are called ‘other’.

List ignored or untracked
1
2
3
4
$ git ls-files --others
.DS_Store
ignoredFile
untracked

This command show us, all others files, without ignored files. Option exclude-standard means that standard git exclusion files are included.

List others files, without ignored files
1
2
$ git ls-files --others --exclude-standard
untracked

This command show us, all files that are ignored.

List all ignored files
1
2
3
$ git ls-files --ignored --others --exclude-standard
.DS_Store
ignoredFile

In my global git ignore file, there is a rule to ignore all .DS_Store files. In my local git ignore file, there is a rule to ignore ignoredFile file.

Comments