Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git count files in the staged index

Tags:

git

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

I've tried:

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.

like image 315
Bradley Avatar asked Jul 01 '10 23:07

Bradley


People also ask

How do I find files in my staging area?

simply typing git status gives you a list of staged files, a list of modified yet unstaged files, and a list of untracked files. @houtanb, git status shows you a diff. (It doesn't show you all staged files).

How do I see staged files in git?

If your changes are already staged, then there's no difference to show. But there's a command line option that will show you staged changes if you specify it: git diff --staged . With the --staged option, git diff will compare your staged changes against the previous commit.


2 Answers

If you want something a script can use:

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

If you want something human readable:

git diff --cached --stat

like image 189
mkarasek Avatar answered Oct 12 '22 22:10

mkarasek


This worked for me:

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

it returns a number

like image 44
chrisjlee Avatar answered Oct 12 '22 23:10

chrisjlee