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
KSKoutsouflakis Stefanos <koutsouflakis.stefanos@proton.me>
Date
Dec 11, 2025, 16:33 UTC
Message-ID
<lVqXkS_Nc_hxtxMq3nevB6dCfPgh-qw9A6dLROQqGqN1_iqDONXeGQmp91hGmVTmaSIqGy5QVMC5OuzJmuULP-rUWcqBSv_L8pnLgPjoDsM=@proton.me>
In-Reply-To
<d318c46c-fbc3-4e47-8c3f-165ca9a26225@kdbg.org>
On Thursday, December 11th, 2025 at 14:34, Johannes Sixt <j6t@kdbg.org> wrote:
Show 22 quoted lines
> Am 11.12.25 um 12:53 schrieb Koutsouflakis Stefanos:
> 
> > On Wed, Dec 10, 2025 at 10:24 PM Junio C Hamano gitster@pobox.com wrote:
> > 
> > > The thinking has always been "'--hard' means what it says! HARD
> > > removes things harder than other modes---there is [no] need to add
> > > '--force' to it".
> > 
> > I agree that "--hard" conveys serious intent. But I would argue
> > there is a meaningful difference between "lose your uncommitted
> > changes" and "lose your entire project".
> > 
> > To be clear, I'm addressing a very narrow scenario:
> > the user has run init on an existing codebase, staged files
> > with git add, but has not yet made a first commit. Running
> > reset --hard at this point destroys the entire project
> > with no realistic recovery path. This is almost certainly
> > never intentional.
> 
> I would argue that bad "tutorials" and "recipes" are to blame. I have
> seen far too many that casually suggest `git reset --hard` without
> warning and in an easy to copy-and-paste format.
Agreed. Many users copy-paste their way through Git or use commands
they don't fully understand. That's not the ideal way to interact with 
Git, but they don't deserve do be punished.
 
Show 5 quoted lines
> 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?
> 
> -- Hannes

Good point. Checking for an empty destination tree seems to be the better approach. Refusing to proceed (without providing the option of bypassing it with --force) also seems reasonable, maybe with a helpful message explaining the reason. On a second thought "--hard --force" is a bit redundant, like "rm -rf --really-delete".

Thanks, Stefanos

Previous: Johannes SixtNext: Junio C Hamano
Message 7 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.