Graphite Reviewer is now Diamond

How to list all files in Git

Greg Foster
Greg Foster
Graphite software engineer
Try Graphite


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


This guide will provide comprehensive details on various methods to list files in a Git repository using different criteria and commands.

To list all files currently being tracked by Git in your repository, you can use the git ls-files command. This command is particularly useful for seeing a complete list of files that Git is aware of in the staging area and working directory.

Command:

Terminal
git ls-files
Join 45,000+ developers at top companies
Stop wrestling with Git commands
The Graphite CLI takes all the pain out of Git, allowing you to ship faster and stop googling Git commands.
main
diff1
diff2

If you want to list all files in a specific branch without switching to it, you can use the git ls-tree command along with the branch name. This command shows you all the files and directories in the tree structure of a branch.

Command:

Terminal
git ls-tree -r branch_name --name-only

Here, -r stands for recursive, so it lists all files in all directories, and --name-only simplifies the output to show just filenames.

To list all files as they were in a specific commit, you can use a similar approach to listing files in a branch, but instead, you use the commit hash.

Command:

Terminal
git ls-tree -r commit_hash --name-only

This will output all the files that were present in that particular commit.

If you want to see every file that has ever been part of the repository (including deleted and moved files), you'll need to use the git log command with some additional flags.

Command:

Terminal
git log --pretty=format: --name-only --diff-filter=A | sort -u

This command lists all files that have ever been added to the repository. The --diff-filter=A option filters for added files, while sort -u sorts the list and removes any duplicates.

You can also list all of the files that have been staged (added but not yet committed) by running:

Command:

Terminal
git diff --name-only --cached

This will show you all files that are currently staged, omitting all other files in the repo.

Join 45,000+ developers at top companies
The best engineers use Graphite to simplify Git
Engineers at Vercel, Snowflake & The Browser Company are shipping faster and staying unblocked with Graphite.
main
diff1
diff2

Sometimes you might need more control or more specific information about the files in your repository.

You can use git log to list files based on specific criteria such as author, date, or type of change.

Example:

Terminal
git log --author="Author Name" --pretty=format: --name-only | sort -u

This command lists all files committed by a specific author.

You can also filter files based on the type of change (added, modified, deleted) across the history of the repository.

Command:

Terminal
git log --pretty=format: --name-status

This command shows all files along with their status (added, modified, deleted).

  • Regularly clean up local and remote branches to maintain a manageable list of files when checking different branches.
  • Use .gitignore effectively to keep unwanted files out of your tracked files list.

For more information on listing files in Git, see the official Git documentation.

The Graphite CLI is designed to simplify common Git workflows by providing a more intuitive, visually-driven interface compared to native Git commands. It streamlines tasks like viewing branch dependencies and commit ancestry, helping developers better understand their repository structure without sifting through extensive raw Git log output.

The Graphite CLI offers a flexible way to review your repository’s commit history through its gt log command . These commands log your stacks and come in three forms:

  • gt log: Displays all tracked branches along with their dependency relationships, providing more detailed information about each branch.
  • gt log short: Displays all tracked branches and their dependency relationships in a more concise format.
  • gt log long: Ignores all options and displays a graph of the commit ancestry of all branches, offering a comprehensive visual overview.

Additionally, the default aliases make it even easier to use these commands:

  • gt ls is an alias for gt log short.
  • gt ll is an alias for gt log long.

Here's a visual example of what you'll see in the terminal when you run gt log with Graphite:

screenshot of gt log

For further details and advanced usage options, please refer to the Graphite CLI command reference.

Built for the world's fastest engineering teams, now available for everyone