Re: 'git commit --short' without touching index?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]