git count files in the staged index

I’m trying to figure out how to easily count the files in my uncommitted index.

I’ve tried:

  • Perform git deep scan in order to compare files for real
  • Visual Studio 2013 and Git 2.4
  • “ERROR:gitosis.serve.main:Repository read access denied” when trying to clone a git repo
  • What is the best way to convert a TFS project to a git repo
  • How to make dependencies between merged patch and before merged patch in gerrit?
  • SSH Fingerprint not authorized on Heroku after git restore
  • git status | grep '#' | wc -l

    but there are a few lines that start with # that don’t represent changed files. Anyone got anything better? Figured there had to be a flag for git status to do this.

    Even tools like GitX don’t easily allow you to select the staged files/directories and see how many of them there are.

  • Is it advisable to include the contents of vendor/cache in Git in a Rails 3.2 application?
  • Gitlab key format issue
  • Disable auto-completion of remote branches in Zsh?
  • Splitting a set of files within a git repo into their own repository, preserving relevant history
  • Error with Git SVN clone
  • How can I show the contents of a file at a specific state of a git repo?
  • 4 Solutions collect form web for “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

    This worked for me:

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

    it returns a number

    Try git status -s:

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

    M directly after start of line (^) indicates a staged file. “^ M” would be an unstaged but changed file.

    For what it’s worth, I prefer:

    git diff --stat | tail -n1

    Outputs something like:

    10 files changed, 74 insertions(+), 123 deletions(-)
    Git Baby is a git and github fan, let's start git clone.