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

后端 未结 7 893
广开言路
广开言路 2020-12-31 00:55

I\'m using msysgit (1.7.9), and I\'m looking for the right invocation of the git ls-files command to show just the (tracked) files and directories at the curren

7条回答
  •  爱一瞬间的悲伤
    2020-12-31 01:57

    I'm surprised this is so hard... but don't get me started on my griping about git.

    A variant on jthill's answer seems to be aliasable (hey, I'm a linguist, I have a license to make new words). The variant is

    ls -d `git ls-tree HEAD | sed -e "s/^.*\t//"`
    

    This uses 'ls' to format the output, so you get color coding (if you use that), etc. It also works as an alias:

    alias gitls='ls -d `git ls-tree HEAD | sed -e "s/^.*\t//"`'
    

    FWIW, you can also alias the recursive command, so that you used the 'ls' formatting (e.g. if your path+filenames aren't too long, you'll get two column output, color coding of executables, etc.)

    alias gitls-r='ls `git ls-files`'
    

提交回复
热议问题