Finding total lines of code in your project
Mohammad Aziz
Posted on April 11, 2020
You may be a new joiner to your organization or someone who is already working in a firm for many years. One day you're sitting on your chair and suddenly one thought came into your mind.
How many lines of code are in my project? 🤔
One challenge could be that you might be relying on external packages, preferably open-sourced, or some code coverage folder might be already present from the last time you have run your test. You can delete them, fair point but then you have to create the coverage or install all of the dependencies again. Only if there is a way adhere my .gitignore
rules then the world could have been a little more perfect.
Turns out, there is a way out 💡
Entering git
, like always!
git ls-files | xargs cat | wc -l
Running this command will give you the total number of lines in your project.
There are two parts in this process, well, as you can see there are three parts but you can think the last two commands as singular. The last two commands are there basically to count the number of lines only. The first command is a kind of interesting one which lists all the files that currently present in your repository and excludes the one who is ignored in your .gitignore
file. So there you have it.
You can also tweak git ls-files command to check the lines for specific extensions.
Posted on April 11, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.