Count number of lines in a git repository

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

    xargs will do what you want:

    git ls-files | xargs cat | wc -l
    

    But with more information and probably better, you can do:

    git ls-files | xargs wc -l
    
    0 讨论(0)
  • 2020-12-02 04:03
    : | git mktree | git diff --shortstat --stdin
    

    Or:

    git ls-tree @ | sed '1i\\' | git mktree --batch | xargs | git diff-tree --shortstat --stdin
    
    0 讨论(0)
  • 2020-12-02 04:06

    I was playing around with cmder (http://gooseberrycreative.com/cmder/) and I wanted to count the lines of html,css,java and javascript. While some of the answers above worked, or pattern in grep didn't - I found here (https://unix.stackexchange.com/questions/37313/how-do-i-grep-for-multiple-patterns) that I had to escape it

    So this is what I use now:

    git ls-files | grep "\(.html\|.css\|.js\|.java\)$" | xargs wc -l

    0 讨论(0)
  • 2020-12-02 04:06

    Try:

    find . -type f -name '*.*' -exec wc -l {} + 
    

    on the directory/directories in question

    0 讨论(0)
提交回复
热议问题