views:

54

answers:

3

During make, I create string fields which I embedded in the linked output. Very useful.

Other than a complex sed/grep parsing of the git status command, how can I easily determine if files in the workspace have been modified according to git?

+5  A: 

git ls-files -m

To find this you could have browsed through git help -a.

Christoffer Hammarström
This is perfect.
Jamie
@Jamie: Files with staged (but uncommitted) changes will not show up with `git ls-files -m`, which may or may not be what you want.
Chris Johnsen
Ah. Thanks for your input. Truthfully, `git ls-files -m` isn't what I want, but it does answer my specific question. +1 for comment and answer though.
Jamie
+5  A: 

git status --porcelain seems to give a nice parsable output.

MDCore
Very nice. Will be useful for other reasons.
Jamie
+1  A: 

If you just want a plain “Are there any differences from HEAD?”:

git diff-index --quiet HEAD

If the exit code is 0, then there were no differences.

If you want “What files have changed from HEAD?”:

git diff-index --name-only HEAD

If you want “What files have changed from HEAD, and in what ways have they changed (added, deleted, changed)?”:

git diff-index --name-status HEAD

Add -M (and -C) if you want rename (and copy) detection.

These commands will check both the staged contents (what is in the index) and the files in the working tree. Alternatives like git ls-files -m will only check the working tree against the index (i.e. they will disregard any staged (but uncommitted) content that is also in the working tree).

Chris Johnsen