我如何计算在一个git存储库中所有文件中出现的总行数?

Git ls-files给了我一个由Git跟踪的文件列表。

我正在找一个命令来隐藏所有这些文件。类似的

git ls-files | [cat all these files] | wc -l

当前回答

从时钟1.68开始工作:

cloc——风险投资= git

其他回答

如果你想找到非空行总数,你可以使用AWK:

git ls-files | xargs cat | awk '/\S/{x++} END{print "非空行总数:",x}'

它使用regex计算包含非空格字符的行数。

Xargs会让你把所有文件放在一起,然后把它们传递给wc,就像你问的那样:

git ls-files | xargs cat | wc -l

但是跳过中间的cat会给你更多的信息,可能会更好:

git ls-files | xargs wc -l
: | git mktree | git diff --shortstat --stdin

Or:

git ls-tree @ | sed '1i\\' | git mktree --batch | xargs | git diff-tree --shortstat --stdin

我在玩cmder (http://gooseberrycreative.com/cmder/),我想计算html,css,java和javascript的行数。虽然上面的一些答案是有效的,或者grep中的模式没有-我在这里(https://unix.stackexchange.com/questions/37313/how-do-i-grep-for-multiple-patterns)发现我必须转义它

这就是我现在用的:

git ls-files | grep " \ (html css |。\ |。js |。java \)美元“| xargs厕所-

Carl Norum的答案假设没有带空格的文件,IFS的一个字符是制表符和换行符。解决方案是用NULL字节终止该行。

 git ls-files -z | xargs -0 cat | wc -l