How to list all text (non-binary) files in a git repository?

自闭症网瘾萝莉.ら 提交于 2019-11-28 23:26:10
git grep --cached -Il ''

lists all non-empty regular (no symlinks) text files:

  • -I: don't match the pattern in binary files
  • -l: only show the matching file names, not matching lines
  • '': the empty string makes git grep match any non-empty file
  • --cached: also find files added with git add but not yet committed (optional)

Or you could use How to determine if Git handles a file as binary or as text? in a for loop with git ls-files.

TODO empty files.

Find all binary files instead: Find all binary files in git HEAD

Tested on Git 2.16.1 with this test repo.

A clever hack to achieve this: listing all non-binary files that contains carriage returns

$ git grep --cached -I -l -e $'\r'

For my case, an empty string works better:

$ git grep --cached -I -l -e $''

Took it from git list binary and/or non-binary files?.

The standard method for listing non-ignored files is:

git ls-files --exclude-standard --cached

But, as you seen, it lists all versioned files.

One workaround could be to define in a separate file "exclude_binaries" an exclusion pattern in order to match all binaries that you know of.

git ls-files --exclude-standard --cached \
--exclude-from=/path/to/`exclude_binaries`

That would be a less complex find, but it doesn't provide a fully automated way to list non-binary files: you still have to identify and list them in a separate pattern file.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!