git count files in the staged index

If you want something a script can use:

git diff --cached --numstat | wc -l

If you want something human readable:

git diff --cached --stat


Try git status -s:

git status -s | egrep "^M" | wc -l

M directly after start-of-line (^) indicates a staged file. ^ M, with a space, would be an unstaged but changed file.


This worked for me:

git status | grep 'modified:' | wc -l

it returns a number


For what it's worth, I prefer:

git diff --stat | tail -n1

Outputs something like:

10 files changed, 74 insertions(+), 123 deletions(-)

Tags:

Git