git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Eric Raible <raible@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: RFC: perhaps a "new file" should not be deleted by "git reset --hard"
Date: Thu, 11 Sep 2008 14:34:43 -0700	[thread overview]
Message-ID: <7vd4jas6x8.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <loom.20080911T204256-821@post.gmane.org> (Eric Raible's message of "Thu, 11 Sep 2008 20:50:27 +0000 (UTC)")

Eric Raible <raible@gmail.com> writes:

> Yes, you have a 100% correct understand of what I'm trying to say.
> But can you see a downside to "git reset --hard" treating newly
> added files as "git reset"?

Of course.  The --hard option is called --hard without inviting short
option for a reason.

I am actually somewhat sympathetic to your point, but you would want
"reset --hard" to remove that path when a path does not exist in the HEAD
but in index in other cases.  And it is my experience (and I presume you
can guess I have longer git experience than any of you ;-) that far more
often than not that is what is desirable.

Consider:

 (1) Your branch does not have "path";

 (2) You once thought you want addition of the "path" made in another
     branch;

 (3) So you did:

    $ git checkout another -- path

 (4) After more hacking, it turns out that the avenue you chose to reach
     your goal, including the addition of the "path", was a mistake, and
     you regret having wasted some time.  You want to go back to the
     current HEAD:

    $ git reset --hard

The state after (3) is "HEAD does not have path, index and work tree has
it".  In step (4) you would want "git reset --hard" to get rid of such a
path.

And it is no different from the case where you add the path manually to
the index.  Both are "you thought you wanted it, but you changed your
mind".

Another example is getting rid of crufts from a conflicted merge.  It may
bring in many new paths in your index and the working tree.  You would
want a "git reset --hard" to get rid of all of them.  Not removing the
paths that are not in HEAD but in index and working tree is far worse in
this case because merging is often done from other people's tree that you
may not be familiar with (i.e. you wanted to study their tree after
merging), so it is harder for you to hand-clean after "reset" if a hard
reset does not do it for you.

  reply	other threads:[~2008-09-11 21:36 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-10 19:12 RFC: perhaps a "new file" should not be deleted by "git reset --hard" Eric Raible
     [not found] ` <eafc0afe0809101912v72916d3hce9ae5d6812f0db8@mail.gmail.com>
2008-09-11  2:14   ` Changsheng Jiang
2008-09-11  2:38     ` Elijah Newren
2008-09-11 20:50       ` Eric Raible
2008-09-11 21:34         ` Junio C Hamano [this message]
2008-09-11 22:19           ` Eric Raible
2008-09-11 23:04             ` Jeff Whiteside
2008-09-11 23:29               ` Eric Raible
2008-09-11  2:46   ` Eric Raible
2008-09-11  6:05     ` Changsheng Jiang
2008-09-11  6:15       ` RFC: perhaps a Eric Raible
2008-09-11 16:32       ` RFC: perhaps a "new file" should not be deleted by "git reset --hard" Elijah Newren
     [not found]         ` <3ab397d0809111022m24c81bd9y2520f6be478babd3@mail.gmail.com>
2008-09-11 21:24           ` Eric Raible
2008-09-11 23:39             ` Miklos Vajna
2008-09-11 23:49               ` Eric Raible
2008-09-12 15:41                 ` Miklos Vajna
2008-09-11  6:14 ` Mike Hommey
2008-09-11 20:26   ` Eric Raible

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=7vd4jas6x8.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=raible@gmail.com \
    /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).