Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a count of all the files in a git repository?

Tags:

git

How would you get a count of all the files currently in a git repository?

like image 615
Dan Rigby Avatar asked Feb 27 '12 17:02

Dan Rigby


People also ask

How do I get a list of files in git?

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.

What is git count?

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.

How do I track files in git?

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.


3 Answers

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:

  • The git ls-files command by itself prints out a list of all the tracked files in the repository, one per line.
  • The | operator funnels the output from the preceding command into the command following the pipe.
  • The 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.

like image 193
Dan Rigby Avatar answered Nov 11 '22 20:11

Dan Rigby


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
like image 34
user40176 Avatar answered Nov 11 '22 19:11

user40176


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...

like image 4
Ben Winding Avatar answered Nov 11 '22 21:11

Ben Winding