Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count unstaged files in git?

Tags:

git

windows

I've found a way to count the staged files. However, I'd like to get a count of the exact opposite, i.e. to learn how many files that are in the red.

When I execute git status, I see I deleted a bunch of file. However, I'd like to know how many that is. Then, I will go git reset in the same branch and check the number of tracked files (now in green, up to date). That way, I can learn how many junky files I had in my repo that wasn't tracked.

Surprisingly, googling how to count unstaged files gave no hits, so I wonder if I'm perhaps missing something very trivial at this ungodly early hour.

like image 514
Konrad Viltersten Avatar asked Aug 31 '25 02:08

Konrad Viltersten


1 Answers

The exact command to do this would be:

git ls-files --others --exclude-standard | wc -l

The --others option will include the untracked files. --exclude-standard option will ignore the files ignored by .gitignore

Piping to wc -l will return a count of the output of ls-files

like image 92
Coffee_Addict Avatar answered Sep 02 '25 15:09

Coffee_Addict