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
If you go to the graphs/contributors page, you can see a list of all the contributors to the repo and how many lines they've added and removed.
To use cloc simply type cloc followed by the file or directory which you wish to examine. Now lets run cloc on it. As you can see it counted the number of files, blank lines, comments and lines of code. Another cool feature of cloc is that can even be used on compressed files.
How to count lines of code for the whole Bitbucket instance. It returns the number of lines added and deleted. So, to get the total, you'll simply need to subtract the number of deleted from the added.
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(+)
.
xargs
will let you cat
all the files together before passing them to wc
, like you asked:
git ls-files | xargs cat | wc -l
But skipping the intermediate cat
gives you more information and is probably better:
git ls-files | xargs wc -l
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With