Count number of lines in a git repository

Dogbert picture Dogbert · Jan 27, 2011 · Viewed 363.9k times · Source

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.

I'm looking for a command to cat all those files. Something like

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

Answer

Carl Norum picture Carl Norum · Jan 27, 2011

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