如何列出git存储库中的所有文本(非二进制)文件? [英] How to list all text (non-binary) files in a git repository?
问题描述
我有一个存储库,其中包含许多在.gitattributes
中标记为二进制"的自动生成的源文件(已签入,因为并非每个人都可以使用生成器工具).此外,该回购协议在被忽略的目录中有很多源代码文件(同样是在构建过程中生成的),以及许多实际的二进制文件(例如,诸如图标之类的小资源文件).
I have a repository with a lot of autogenerated source files I've marked as "binary" in .gitattributes
(they are checked in because not everyone has access to the generator tools). Additionally, the repo has a lot of source-ish files in ignored directories (again, generated as part of the build processes), and a number of actual binary files (e.g. little resource files like icons).
我现在想在回购中查找所有非自动生成且不可忽略的文件.我以为我会用find
和许多排除来做到这一点,但是现在我有一个带有许多子句的可怕的find
语句(它仍然不能很好地完成这项工作). git ls-files
可以工作,但是显示所有二进制文件而没有区别,我必须将它们过滤掉.
I'd now like to find all the non-auto-generated and non-ignored files in the repo. I thought I'd just do this with find
and a bunch of exclusions, but now I have a horrendous find
statement with a dozen clauses (and it still doesn't perfectly do the job). git ls-files
works but shows me all the binary files without differentiation, which I have to filter out.
所以,我想知道:是否可以运行一个简单的命令,将列出检入到存储库中的每个文件,以及哪个git
认为是文本"文件?
So, I'm wondering: is there a simple command I can run which lists every file checked into the the repo, and which git
considers a "text" file?
推荐答案
git grep --cached -Il ''
列出所有非空的常规(无符号链接)文本文件:
lists all non-empty regular (no symlinks) text files:
-
-I
:与二进制文件中的模式不匹配 -
-l
:仅显示匹配的文件名,不显示匹配的行 -
''
:空字符串使git grep
匹配任何非空文件 -
--cached
:还查找添加了git add
但尚未提交的文件(可选)
-I
: don't match the pattern in binary files-l
: only show the matching file names, not matching lines''
: the empty string makesgit grep
match any non-empty file--cached
: also find files added withgit add
but not yet committed (optional)
或者您可以使用如何确定Git是将文件处理为二进制文件还是文本文件?在带有git ls-files
的for循环中.
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
.
待办事项空文件.
相反,查找所有二进制文件:在git头
Find all binary files instead: Find all binary files in git HEAD
在Git 2.16.1上使用此测试存储库进行了测试
Tested on Git 2.16.1 with this test repo.
这篇关于如何列出git存储库中的所有文本(非二进制)文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!