How would you get a count of all the files currently in a git repository?
This command will list the files that are being tracked currently. If you want a list of files that ever existed use: git log --pretty=format: --name-only --diff-filter=A | sort - | sed '/^$/d'This command will list all the files including deleted files.
DESCRIPTION. This counts the number of unpacked object files and disk space consumed by them, to help you decide when it is a good time to repack.
When you start a new repository, you typically want to add all existing files so that your changes will all be tracked from that point forward. So, the first command you'll typically type is "git add ." (the "." means, this directory. So, it will add everything in this directory.) I'll type "git add ." and press Enter.
You can get a count of all tracked files in a git respository by using the following command:
git ls-files | wc -l
Command Breakdown:
git ls-files
command by itself prints out a list of all the tracked files in the repository, one per line.|
operator funnels the output from the preceding command into the command following the pipe.wc -l
command calls the word count (wc) program. Passing the -l
flag asks it to return the total number of lines.Note: This returns a count of only the tracked files in the repository meaning that any ignored files or new & uncommitted files will not be counted.
If you came here looking for a way to do this for a repo hosted on github without cloning it, you can do this:
svn ls -R https://github.com/exampleproject/branches/master | wc -l
Just to build on the accepted answer, you can also filter which types of files you want to count.
Count only .json
files
# Will output only json file paths
git ls-files "./*.json" | wc -l
Count only .c
files
git ls-files "./*.c" | wc -l
A fairly useful way to gauge what languages are common in a repo...
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