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

Re: [RFC] reset --hard: warn before discarding staged content with no commit history

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 12, 2025, 03:24 UTC
Message-ID
<xmqqzf7ocrhk.fsf@gitster.g>
In-Reply-To
<d318c46c-fbc3-4e47-8c3f-165ca9a26225@kdbg.org>
Johannes Sixt <j6t@kdbg.org> writes:
Show 6 quoted lines
> 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" :-/

Previous: Koutsouflakis StefanosNext: Koutsouflakis Stefanos
Message 8 of 13 in “[RFC] reset --hard: warn before discarding staged content with no commit history”
  1. Koutsouflakis StefanosDec 10, 2025
  2. Junio C HamanoDec 11, 2025
  3. Eric SunshineDec 11, 2025
  4. Junio C HamanoDec 11, 2025
  5. Koutsouflakis StefanosDec 11, 2025
  6. Johannes SixtDec 11, 2025
  7. Koutsouflakis StefanosDec 11, 2025
  8. Junio C HamanoDec 12, 2025
  9. Koutsouflakis StefanosDec 14, 2025
  10. Štefan BalogDec 14, 2025
  11. Junio C HamanoDec 14, 2025
  12. Koutsouflakis StefanosDec 15, 2025
  13. D. Ben KnobleDec 12, 2025

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.