Thread (4 messages) 4 messages, 3 authors, 2016-06-15

Best way to check for a "dirty" working tree?

From: Dirk Süsserott <hidden>
Date: 2016-06-15 22:51:28

Hi list,

I have a script which moves data from somewhere to my local repo and
then checks it in, like so:

-----------
mv /tmp/foo.bar .
git commit -am "Updated foo.bar at $timestamp"
-----------

However, before overwriting "foo.bar" in my working directory, I'd like
to check whether my working tree is dirty (at least "foo.bar").

I tried

A) if ! git diff-index --quiet HEAD -- foo.bar; then
       dirty=1
   fi

and

B) if ! git diff --quiet -- foo.bar; then
       dirty=1
   fi

Both A) and B) work. But which one is better/faster/more reliable? Or is
there a better solution? For my purpose, I cannot see a difference
between diff and diff-index, except the syntax.

Cheers,
    Dirk
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help