git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Best way to check for a "dirty" working tree?
@ 2011-06-11 14:54 Dirk Süsserott
  2011-06-12 12:23 ` Ramkumar Ramachandra
  2011-06-13 22:22 ` Jonathan Nieder
  0 siblings, 2 replies; 4+ messages in thread
From: Dirk Süsserott @ 2011-06-11 14:54 UTC (permalink / raw)
  To: Git Mailing List

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-06-14 13:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-11 14:54 Best way to check for a "dirty" working tree? Dirk Süsserott
2011-06-12 12:23 ` Ramkumar Ramachandra
2011-06-13 22:22 ` Jonathan Nieder
2011-06-14 13:28   ` Dirk Süsserott

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).