Re: Dangers of reset --hard (Re: Implicit stashes)

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

 



On Wed, 2010-06-30 at 00:13 -0500, Jonathan Nieder wrote:
> John Tapsell wrote:
> 
> > $ git reset --hard
> >
> > I know this seems very explicit to delete changes, but I myself have
> > done this and accidentally lost changes.  For example, I write a unit
> > test and don't commit it in on purpose because I know that it
> > currently fails and I want to test it against older versions.  I
> > carefully git checkout older versions to find if the unit test fails,
> > then in stupidity reset back to origin/master ..
> 
> Aside: I assume you already know about it, but still I cannot help but
> take the opportunity to advertise ‘git reset --keep’.  I was added
> fairly recently (1.7.1 rc0) and I find myself annoyed when on machines
> without it because of almost exactly this use case.

I tend to want "do a git reset --hard, but fail if anything would be
lost". The use-case here is that when I reset --hard, I want a
completely clean copy- but I don't want to accidentally lose anything.

This can probably be achieved with something like:
git diff-files --quiet &&
  git diff-index --quiet HEAD &&
  git diff-index --cached --quiet HEAD ||
  git reset --hard "$@"

I've got a half-done patch sitting at home which adds -g, --gentle to
"git reset", which is intended to do exactly that- but my git-fu is not
very strong on the C end of things, so for the foreseeable future it
will remain an idea without a working implementation.

--
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]