git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: RFC: perhaps a "new file" should not be deleted by "git reset --hard"

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 11, 2008, 21:34 UTC
Message-ID
<7vd4jas6x8.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<loom.20080911T204256-821@post.gmane.org>
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.

Previous: Eric RaibleNext: Eric Raible
Message 7 of 18 in “RFC: perhaps a "new file" should not be deleted by "git reset --hard"”
  1. Eric RaibleSep 10, 2008
  2. Mike HommeySep 11, 2008
  3. Eric RaibleSep 11, 2008
  4. Changsheng JiangSep 11, 2008
  5. Elijah NewrenSep 11, 2008
  6. Eric RaibleSep 11, 2008
  7. Junio C HamanoSep 11, 2008
  8. Eric RaibleSep 11, 2008
  9. Jeff WhitesideSep 11, 2008
  10. Eric RaibleSep 11, 2008
  11. Eric RaibleSep 11, 2008
  12. Changsheng JiangSep 11, 2008
  13. Eric RaibleSep 11, 2008
  14. Elijah NewrenSep 11, 2008
  15. Eric RaibleSep 11, 2008
  16. Miklos VajnaSep 11, 2008
  17. Eric RaibleSep 11, 2008
  18. Miklos VajnaSep 12, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.