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

Re: Prevent git reset --hard from losing data

From
Mirko Faina <mroik@delayed.space>
Date
Nov 20, 2026, 21:09 UTC
Message-ID
<awC0MJDYS88yEtgm@exploit>
In-Reply-To
<20261120145444.13061eb7@gandalf.local.home>
On Fri, Nov 20, 2026 at 02:54:44PM -0500, Steven Rostedt wrote:
> Too many times I do a "git reset --hard" in the wrong directory and end up
> losing uncommitted changes. Is there a way to add a configuration to have
> that command check if there's any uncommitted changes and ask if you really
> want to do the reset?

You could just reset without the --hard option and restore what you don't want to keep. Otherwise there's the --keep option that aborts the reset if there's local changes, but you'd have to remember to type it out every time.

Maybe a configuration variable that makes the --keep behaviour the default could be added with a --force flag to override it.

Previous: Steven RostedtNext: Junio C Hamano
Message 2 of 4 in “Prevent git reset --hard from losing data”
  1. Steven RostedtNov 20, 2026
  2. Mirko FainaNov 20, 2026
  3. Junio C HamanoNov 20, 2026
  4. Steven RostedtNov 20, 2026

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.