git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Daniel <friedan@muon.rutgers.edu>
Cc: git@vger.kernel.org
Subject: Re: 'git commit --short' without touching index?
Date: Sat, 3 Jul 2010 05:17:48 -0400	[thread overview]
Message-ID: <20100703091748.GA11714@sigill.intra.peff.net> (raw)
In-Reply-To: <loom.20100703T102242-536@post.gmane.org>

On Sat, Jul 03, 2010 at 08:30:31AM +0000, Daniel wrote:

> 'git commit --short' touches .git/index ('--short' implies '--dry-run').
> 
> Is there any equivalent command that does not touch .git/index?
> 
> I'm using 'git commit --short' in a script to check if the repository needs
> attention.  At present, it touches .git/index, which causes
> unnecessary activity in another script running rsync.

If you are just calling "git commit --short" without arguments (i.e.,
you care about the current state, not about "what would happen if I
commit with these arguments"), then you probably want "git status".
Also, you probably should use "git status --porcelain", which is the
same as --short but is guaranteed not to change in the future.

However, both "status" and "commit --dry-run" will opportunistically
refresh the index. If you don't want to touch the index at all, you can
use a combination of:

  # show changes between HEAD and index
  git diff-index HEAD

  # show changes between index and working tree
  git diff-files

  # show untracked files
  git ls-files --exclude-standard -o

One thing you will find, though, is that not refreshing the index means
that stat-dirty files (e.g., ones which have no content changed but
which have had their timestamps changed) will appear the diff-files
above.

I don't think there is a simple way to tell "git status" to refresh the
index internally, but not to write it out. It will do this if it doesn't
have write permissions, but chmod'ing your index before running the
script seems like an awful hack. You could refresh to a temporary index,
but that also seems like a hack.

It would be nice if the index-refreshing code only wrote to the index if
there was something worth writing. I'm not sure how hard that would be
to implement, though.

-Peff

  reply	other threads:[~2010-07-03  9:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-03  8:30 'git commit --short' without touching index? Daniel
2010-07-03  9:17 ` Jeff King [this message]
2010-07-03 10:08   ` friedan
2010-07-05 20:10   ` Junio C Hamano
2010-07-05 20:56     ` Jeff King
2010-07-05 21:28       ` Junio C Hamano
2010-07-06 12:10         ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100703091748.GA11714@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=friedan@muon.rutgers.edu \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).