tags:

views:

22

answers:

2

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.

A: 

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.

tobiw
Thanks, that returned 0 but `git status -s | egrep "^M " | wc -l` worked. I think the space needs to be on the other side of the "M" in the regex.
Bradley
Ah and to include other types of changes (added, renamed, created, deleted): `git status -s | egrep -c "^[MARCD]"`
Bradley
+1  A: 

If you want something a script can use:

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

If you want something human readable:

git diff --cached --stat

mkarasek