// Reference: http://stackoverflow.com/questions/4822471/count-number-of-lines-in-a-git-repository | |
$ git ls-files | xargs wc -l |
This comment has been minimized.
This comment has been minimized.
Tried this command on Mac and got "xargs: wc: Argument list too long" error. Is it because the git repo is too big? |
This comment has been minimized.
This comment has been minimized.
Perfect! |
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
@shic @mandiwise you can do the following if it's "too long" :)
|
This comment has been minimized.
This comment has been minimized.
does this reads the files from sub-directories ? |
This comment has been minimized.
This comment has been minimized.
Yes it does @dextel2. |
This comment has been minimized.
This comment has been minimized.
It's awesome |
This comment has been minimized.
This comment has been minimized.
This is great, thanks! |
This comment has been minimized.
This comment has been minimized.
Thank you. It's very helpful |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Awesome! |
This comment has been minimized.
This comment has been minimized.
Does anyone know if there is a way to exclude certain file types from this command? For example get lines of code for a repo but don't include certain file extensions (i.e. .png, .jpg, etc). |
This comment has been minimized.
This comment has been minimized.
@darrylgrant Just use |
This comment has been minimized.
This comment has been minimized.
thank you |
This comment has been minimized.
This comment has been minimized.
What do I need to do if I want to exclude multiple file types? Is it going to be something like this? git ls-files | grep -v .{js,css,html} | xargs wc -l |
This comment has been minimized.
This comment has been minimized.
You're the best. |
This comment has been minimized.
This comment has been minimized.
Perfect! |
This comment has been minimized.
This comment has been minimized.
Lovely! |
This comment has been minimized.
This comment has been minimized.
Super cool! |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
Thank you! However, the console shows a large file list, then I also tried piping into a file like @funilrys did it, but the output was the same |
This comment has been minimized.
This comment has been minimized.
@PhilLab If it's really like that you can then do something like this ... git ls-files > listOfFiles
cat listOfFiles | xargs wc -l | grep total | xargs | awk '{lineNumber+=$1}END{print lineNumber}` |
This comment has been minimized.
This comment has been minimized.
PowerShell |
This comment has been minimized.
This comment has been minimized.
I get something liek this for every file:
|
This comment has been minimized.
This comment has been minimized.
Thank you I remixed it to exclude certain types of files (like images) and folders (like external dependencies living in the repo) and put it in a git alias:
then
|
This comment has been minimized.
This comment has been minimized.
FWIW: I used the following code to find the number of scripts, and lines of code. all_files = [os.path.join(path, name) for path, subdirs, files in os.walk(os.getcwd()) for name in files if '.py' in name] print(f'Number of python scripts',len(all_files)) global_count = 0 print('Total number of lines of code:',global_count)` |
This comment has been minimized.
This comment has been minimized.
Hi all, Quick question: Is there a technique where I could count the number of files (under a specific folder) in a GitHub repo? P.S. I am looking to add a "file counter" to a folder in GitHub repo which has numerous files coming in every day. |
This comment has been minimized.
This comment has been minimized.
@SandeepAswathnarayana it is almost the same command without This will return the number of all versionned files: you can limit what folders you want to include with:
you can exclude some folders and/or files with: |
This comment has been minimized.
This comment has been minimized.
Thanks for reverting, @Em-AK. I want to add a code snippet to the GitHub folder which tracks the number of files in real-time so it's visible for any user on the repo. Do you have any specific suggestions for the same? |
This comment has been minimized.
This comment has been minimized.
@SandeepAswathnarayana in this case I think it should be possible to run a custom github action on every push to your branch of reference. |
This comment has been minimized.
This comment has been minimized.
Thanks for the input, @Em-AK. I will give this a try using GitHub 'Actions'. I appreciate your time in this regard. Have a splendid week! |
This comment has been minimized.
This comment has been minimized.
Or, try using this app I built https://github.com/CodHeK/analy.se , you can simply drag n drop your project folder, doesn't store your files on a server so is completely safe! |
This comment has been minimized.
This comment has been minimized.
In case anyone needs to do this on a bare repository:
is working for me (or at least giving consistent results to the |
This comment has been minimized.
This comment has been minimized.
This worked perfectly! Thank you so much! |
This comment has been minimized.
This comment has been minimized.
Nice. Thanks for that |
This comment has been minimized.
This comment has been minimized.
What about cloc?
|
This comment has been minimized.
This comment has been minimized.
This is cool ! I want to do this for every commit ever on one of my repositories, is there a way to do that ? How could i loop through every commit ever ? (Only on the master branch) |
This comment has been minimized.
This comment has been minimized.
This was helpful, but I needed to exclude images, and a few other common files. Thought I would "share with the class": git ls-files --exclude-standard -- ':!:**/*.[pjs][npv]g' ':!:**/*.ai' ':!:.idea' ':!:**/*.eslintrc' ':!:package-lock.json' | xargs wc -l
|
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
Thanks |
This comment has been minimized.
This comment has been minimized.
I made an app to do it completely remotely, on a forked repo, without having to clone it - https://klock.herokuapp.com/ |
This comment has been minimized.
This comment has been minimized.
Helpful awesome. |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
perfect thanks! |
This comment has been minimized.
This comment has been minimized.
Thanks!! |
This comment has been minimized.
This comment has been minimized.
Great! |
This comment has been minimized.
This comment has been minimized.
you should try this |
This comment has been minimized.
This comment has been minimized.
Genius |
This comment has been minimized.
This comment has been minimized.
Amazing, thank you! |
This comment has been minimized.
This comment has been minimized.
@PhilLab I had the same problem, but I solved it like this: |
This comment has been minimized.
This comment has been minimized.
Hi All, Any Ide where I can exclude all the comments with the below command $ git ls-files | xargs wc -l I assume that the above command will give you list of lines of code including the comments , Any command to not include comments and only the line of code count. |
This comment has been minimized.
Thank you!
Could not be more simple.