RobertL
RobertL

Reputation: 14874

How can I make git show a list of the files that are being tracked?

Using command line git, how can I make git show a list of the files that are being tracked in the repository?

Upvotes: 772

Views: 368811

Answers (7)

Cyber Networks
Cyber Networks

Reputation: 1

Windows Command Prompt

To find all directories being tracked by Git on a Windows system, you can use the following command in the Command Prompt:

dir /s /b /ad "C:\*" | findstr /i "\\\.git$"

This command retrieves the URLs of all remotes configured in Git repositories and extracts the repository names from the URLs.

Upvotes: -3

milahu
milahu

Reputation: 3539

list files tracked by git, sort by author date

git ls-tree -r --name-only main . | while read -r path; do date=$(git log -n1 --format=format:%aI -- "$path"); echo "$date $path"; done | sort -r | cut -c27-

Upvotes: 0

Tuxdude
Tuxdude

Reputation: 49473

To list all the files currently being tracked under the branch master, use ls-tree:

git ls-tree -r master --name-only

To list all files that have ever existed (i.e. including deleted files):

git log --pretty=format: --name-only --diff-filter=A | sort - | sed '/^$/d'

Upvotes: 904

vonbrand
vonbrand

Reputation: 11791

The files managed by git are shown by git ls-files. Check out its manual page.

Upvotes: 261

Bloody_fool
Bloody_fool

Reputation: 176

You might want colored output with this.

I use this one-liner for listing the tracked files and directories in the current directory of the current branch:

ls --group-directories-first --color=auto -d $(git ls-tree $(git branch | grep \* | cut -d " " -f2) --name-only)

You might want to add it as an alias:

alias gl='ls --group-directories-first --color=auto -d $(git ls-tree $(git branch | grep \* | cut -d " " -f2) --name-only)'

If you want to recursively list files:

'ls' --color=auto -d $(git ls-tree -rt $(git branch | grep \* | cut -d " " -f2) --name-only)

And an alias:

alias glr="'ls' --color=auto -d \$(git ls-tree -rt \$(git branch | grep \\* | cut -d \" \" -f2) --name-only)"

Upvotes: 10

xeruf
xeruf

Reputation: 2990

Building on the existing answers, you can use tree to view it a little prettier:

git ls-tree --full-tree --name-only -r HEAD | tree --fromfile .

You probably want to paginate this:

git ls-tree --full-tree --name-only -r HEAD | tree -C --fromfile . | ${PAGER:-less}

This certainly deserves a place as tree alias in the git config :)

Upvotes: 7

Nathan
Nathan

Reputation: 10306

The accepted answer only shows files in the current directory's tree. To show all of the tracked files that have been committed (on the current branch), use

git ls-tree --full-tree --name-only -r HEAD
  • --full-tree makes the command run as if you were in the repo's root directory.
  • -r recurses into subdirectories. Combined with --full-tree, this gives you all committed, tracked files.
  • --name-only removes SHA / permission info for when you just want the file paths.
  • HEAD specifies which branch you want the list of tracked, committed files for. You could change this to master or any other branch name, but HEAD is the commit you have checked out right now.

This is the method from the accepted answer to the ~duplicate question https://stackoverflow.com/a/8533413/4880003.

Upvotes: 59

Related Questions