how to `git ls-files` for just one directory level.

(late edit for a feature added in Git 1.8.5, after the question and answer were written:)

Git’s pathspecs ordinarily match * with any path substring, including / separators, but you can use shell pathname-matching conventions by adding a magic :(glob) prefix. So to list just the files in the current directory,

git ls-files ':(glob)*'   # just the files in the current directory
git ls-files ':(glob)test/*' # and so on

As a side note, you can do many more things with those magic prefixes, chase that link.

You can also turn on shell-style globbing with the --glob-pathspecs option on the Git command itself, so

$ alias ggit="git --glob-pathspecs"
$ # and a personal favorite:
$ git config --global alias.ls 'ls-files --exclude-standard'
$ # then whenever
$ ggit ls '*'     # note the quoting to bypass the shell's globbing,

Original answer, still works:

I think you want git ls-tree HEAD sed’d to taste. The second word of ls-tree’s output will be tree for directories, blob for files, commit for submodules, the filename is everything after the ascii tab.

Edit: adapting from @iegik’s comment and to better fit the question as asked,

git ls-files . | sed s,/.*,/, | uniq

will list the indexed files starting at the current level and collapse directories to their first component.

Further edit: another way to do it is

git ls-tree `git write-tree` .

and you can use git ls-tree‘s options for some nice seasoning.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)