How to count unstaged files in git?

Viewed 586

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.

2 Answers

in git you can use the command

git status -s -uno | wc -l

if you want to go with powershell use below code

git status -s -uno | Measure-Object -Line

please let me know if it helps you.

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

Related