git ls-files in bare repository
Asked Answered
M

1

48

I want to access a bare git repository, and I want to list all files in the repository.

On a normal git repository I can easily do that by running git ls-files.

Example output:

$ git ls-files
README.md
file1.js
file2.js
file3.js
folder1/file4.js
folder2/file5.js

In a bare git repository this fails silently. It just doesn't return any files (but exits successfully):

$ cd my-bare-repository
$ git ls-files #returns nothing
$ echo $? #print exit code from previous command
$ 0

Now I am aware that I have to provide a meaningful branch or master to display. But how can I actually get this list of the files that I know are in my repository?

Mcclellan answered 18/9, 2014 at 6:58 Comment(0)
G
82

You can try the other command which list files:

git ls-tree --full-tree -r HEAD

According to this comment, the command git ls-tree works in bare repo.

Geodetic answered 18/9, 2014 at 7:2 Comment(5)
Thanks, this works. However, in my current example, I get the same output with and without --full-treeConcha
@JesperRønn-Jensen you also have git ls-tree --full-tree -r --name-only HEAD , to list just the file names, (without leading cruft about permissions and blob SHA values)Geodetic
I am accepting this answer since it's more than I asked for:) +10 for correctness, +10 for fast answer :)Concha
git ls-files works for me in a bare repository with git 2.27, and probably has supported it for a while now.Assertion
@VictorRoetman Yes: it could list files in the index. by default (git-scm.com/docs/git-ls-files) And technically, a bare repository can have an index (github.com/libgit2/libgit2sharp/issues/…). But in my bare repos, git ls-files returns nothing.Geodetic

© 2022 - 2024 — McMap. All rights reserved.