Count number of lines in a git repository

后端 未结 16 2649
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 03:17

How would I count the total number of lines present in all the files in a git repository?

git ls-files gives me a list of files tracked by git.

16条回答
  •  情话喂你
    2020-12-02 03:45

    If you want to find the total number of non-empty lines, you could use AWK:

    git ls-files | xargs cat | awk '/\S/{x++} END{print "Total number of non-empty lines:", x}'

    This uses regex to count the lines containing a non-whitespace character.

提交回复
热议问题