Is there a way to list all files currently under source control in git? (Not just those that have been modified).
5 Answers
If you want to list all files for a specific branch, e.g. master:
git ls-tree -r master --name-only
The -r option will let it recurse into subdirectories and print each file currently under version control. You can also specify HEAD instead of master to get the list for any other branch you might be in.
If you want to get a list of all files that ever existed, see here:
git log --pretty=format: --name-only --diff-filter=A | sort -u
- 6Thanks for the answer. I was looking for this. Note that
git ls-tree -r master --name-onlywould do the same as the first option, without needing thecut. Ah, and you can specifyHEADinstead ofmasterif you just want this list for whatever branch you are currently on.maurits– maurits2012-09-13 10:15:42 +00:00Commented Sep 13, 2012 at 10:15 - 18Running "git ls-files" will save you a few characters :)Zain R– Zain R2015-05-14 21:30:21 +00:00Commented May 14, 2015 at 21:30
- Why was cut given the ending
-? It causes some additional lines to show some files in a second column which are repeats from the first.Adrian– Adrian2019-04-15 13:06:40 +00:00Commented Apr 15, 2019 at 13:06 - 1Replace
masterwith$(git branch | grep \* | cut -d ' ' -f2)for current branch.Eduard– Eduard2019-08-09 19:33:31 +00:00Commented Aug 9, 2019 at 19:33 - @ZainR more importantly, it gives you
-z--eoland other nice optionsCervEd– CervEd2021-05-07 15:42:49 +00:00Commented May 7, 2021 at 15:42
The git ls-files command will do what you need.
Source: http://www.kernel.org/pub/software/scm/git/docs/git-ls-files.html
- 10
git ls-filesinstead ofgit ls-tree -r master --name-onlyis certainly simpler.karatedog– karatedog2013-10-22 08:14:05 +00:00Commented Oct 22, 2013 at 8:14 - 1Sorry but my edit wasn't invalid. In current git there is no
git-ls-filesbinary. There is thegitbinary with thels-filescommand. The link to the documentation is correct in content, but technically for an outdated binary.JonnyJD– JonnyJD2014-01-11 03:09:09 +00:00Commented Jan 11, 2014 at 3:09 - @JonnyJD, probably marked invalid because your edit should be a comment.Ascherer– Ascherer2014-10-12 20:16:17 +00:00Commented Oct 12, 2014 at 20:16
- 2@JonnyJD All Git man-pages are named as
git-commit,git-init,git-ls-files, etc. even though the programs are actually subcommands. There never was agit-ls-filesbinary, most likely. The reasoning is that it's consistent with the external subcommand mechanism, which allows you to register agit foocommand by writing agit-foobinary.anon– anon2017-07-19 16:50:08 +00:00Commented Jul 19, 2017 at 16:50 - 1This is indeed simpler, but on the other hand
git ls-treelets you specify a "tree-ish" (i.e. a branch, tag or commit), whereasgit ls-filesdoesn't offer that option and works therefore only onHEAD.Fabio says Reinstate Monica– Fabio says Reinstate Monica2020-12-15 23:10:12 +00:00Commented Dec 15, 2020 at 23:10
git ls-files will only print files in the current working directory.
If, for instance, you have a git repo for dotfiles (core.worktree = /), then you will have files outside the git root and that simple command won't work anymore.
In short, this will work:
git --git-dir "`git rev-parse --git-dir`" \ -C "`git config core.worktree || pwd`" \ ls-files Example:
mkdir ~/dotfiles cd ~/dotfiles git config core.worktree / # Ignore all files by default, else Git will find all files under "/" echo "*" > .git/info/exclude # Add files at the git repo's root and somewhere in the work tree touch README git add -f README git add -f /etc/ssh/sshd_config # `git status` would now print: # new file: ../../../etc/ssh/sshd_config # new file: README git status git commit -m "Initial commit" # At this point, `git ls-files` prints only: # README git ls-files # But you can print all files inside the work tree. This will print: # etc/ssh/sshd_config # home/yourusername/dotfiles/README git --git-dir "`git rev-parse --git-dir`" -C "`git config core.worktree || pwd`" ls-files If you want paths specified relative to your current (shell) directory, this does the job:
alias gls='git ls-tree -r master --name-only HEAD "`git config core.worktree`"' and in the example above, it would print
README ../../../etc/ssh/sshd_config - In git v2.21,
git ls-filesshows all in the current directory and below. It just doesn't show files that were deleted in the repo.Adrian– Adrian2019-04-15 13:17:35 +00:00Commented Apr 15, 2019 at 13:17
You can also use the gitk interactive repository viewer.
- 3This mentions a tool, but doesn't really answer the "how". Can you expand this into an actionable solution? Just pointing someone in a research direction for them to develop their own solution is more appropriate as a comment. Thanks. from reviewfixer1234– fixer12342018-03-12 22:39:36 +00:00Commented Mar 12, 2018 at 22:39

Please have a look at the image, on right side there are two options patch and Tree. If you select tree, you can view the folder structure for each commit.
- 2Please consider a better commit to screen shot so you do not have to censor as much.Thorbjørn Ravn Andersen– Thorbjørn Ravn Andersen2019-05-14 11:25:44 +00:00Commented May 14, 2019 at 11:25
- While I get the image could have been better, this IS actually a useful answer, and the users first (only!) answer. I'd never realised that
gitkhas this tucked away in its UI.dsz– dsz2021-06-15 01:57:29 +00:00Commented Jun 15, 2021 at 1:57