How can I find out the number of modified files in the index? That is to say, files that show as "modified" when running git status.

I know lots of visual git tools that do this, as well as shell add-ons that show the count next to the prompt, but I just don't see how to do it on the command line in a reasonable way.

Since this questions is about finding the count of changes, there are a couple git commands that do this natively, without having to add | wc -l to your command

You can use git diff with the following args:

  • --stat - generate a diffstat
  • --numstat - shows number of added and deleted lines in decimal notation
  • --shortstat - only the last line of the --stat
$ git diff --stat

src/models/models.ts | 5 +++++
src/utils/git.ts     | 9 ++++++---
2 files changed, 11 insertions(+), 3 deletions(-)
$ git diff --numstat

5       0       src/models/models.ts
6       3       src/utils/git.ts
$ git diff --shortstat

2 files changed, 11 insertions(+), 3 deletions(-)