Count number of lines in a git repository

后端 未结 16 2461
被撕碎了的回忆
被撕碎了的回忆 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:49

    git diff --stat 4b825dc642cb6eb9a060e54bf8d69288fbee4904
    

    This shows the differences from the empty tree to your current working tree. Which happens to count all lines in your current working tree.

    To get the numbers in your current working tree, do this:

    git diff --shortstat `git hash-object -t tree /dev/null`
    

    It will give you a string like 1770 files changed, 166776 insertions(+).

提交回复
热议问题