git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Johannes Sixt <j6t@kdbg.org>
Cc: Koutsouflakis Stefanos <koutsouflakis.stefanos@proton.me>,
	"git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: [RFC] reset --hard: warn before discarding staged content with no commit history
Date: Fri, 12 Dec 2025 12:24:07 +0900	[thread overview]
Message-ID: <xmqqzf7ocrhk.fsf@gitster.g> (raw)
In-Reply-To: <d318c46c-fbc3-4e47-8c3f-165ca9a26225@kdbg.org> (Johannes Sixt's message of "Thu, 11 Dec 2025 13:22:30 +0100")

Johannes Sixt <j6t@kdbg.org> writes:

> Wouldn't the following slightly different scenario warrant a similar
> safety net:
>
>    git commit --allow-empty -m "Initial commit"
>    git add .
>    git reset --hard

Yes, I think everybody has lost new files not in an empty tree but
more often (1) create a new file and add it, (2) make modifications
to existing files, (3) compile, test, debug, get frustrated, and
finally (4) decide to give up and start from scratch, with "reset
--hard".  When (1) is much larger than (2), the sense of loss is
big.

> That said, I have some sympathy for the case. Would it be palatable to
> have `git reset --hard` refuse to do anything if the destination tree is
> empty?

I doubt that special casing an empty tree would fly well.

It is tempting to special case removals, but then I sill am not sure
it is good to do nothing and fail the command after determining that
the operation is a common pitfall of removing a new file that
appears nowhere else.  Unconditionally going interactive is a no-no.

And I do not have any better ideas.  Other than just failing, that is.
But that leads to nonsense combination "--hard --force", just as
idiotic combination as "rm -f -i" :-/

  parent reply	other threads:[~2025-12-12  3:24 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-10 15:01 [RFC] reset --hard: warn before discarding staged content with no commit history Koutsouflakis Stefanos
2025-12-11  3:24 ` Junio C Hamano
2025-12-11  3:59   ` Eric Sunshine
2025-12-11  5:25     ` Junio C Hamano
2025-12-11 11:53   ` Koutsouflakis Stefanos
2025-12-11 12:22     ` Johannes Sixt
2025-12-11 16:33       ` Koutsouflakis Stefanos
2025-12-12  3:24       ` Junio C Hamano [this message]
2025-12-14 13:29         ` Koutsouflakis Stefanos
2025-12-14 13:45           ` Štefan Balog
2025-12-14 23:27           ` Junio C Hamano
2025-12-15  7:22             ` Koutsouflakis Stefanos
2025-12-12 22:14 ` D. Ben Knoble

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=xmqqzf7ocrhk.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    --cc=koutsouflakis.stefanos@proton.me \
    /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).