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

Re: Dangers of reset --hard (Re: Implicit stashes)

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jun 30, 2010, 16:12 UTC
Message-ID
<20100630161217.GE18813@burratino>
In-Reply-To
<1277885972.2498.25.camel@wpalmer.simply-domain>
Will Palmer wrote:
> I tend to want "do a git reset --hard, but fail if anything would be
> lost".

At the risk of being redundant: try git reset --keep. If it succeeds, you can use git diff --cached HEAD and git diff to check how close it was to being equivalent to a hard reset.

> The use-case here is that when I reset --hard, I want a
> completely clean copy- but I don't want to accidentally lose anything.

There is one case when I truly want a completely clean copy (including no untracked files): when I am testing and a bit paranoid. For that, I do something like the following:

 ; mkdir /tmp/test-dir
 ; git archive HEAD | (cd /tmp/test-dir && tar -xf -)
 ; cd /tmp/test-dir

and work from there. I would not be surprised if the needs of your case are different, though.

Previous: Will Palmer
Message 8 of 8 in “Implicit stashes”
  1. John TapsellJun 30, 2010
  2. Joshua JensenJun 30, 2010
  3. John TapsellJun 30, 2010
  4. Sverre RabbelierJun 30, 2010
  5. AlexJun 30, 2010
  6. Dangers of reset --hard (Re: Implicit stashes)Jonathan Nieder, Jun 30, 2010
  7. Will PalmerJun 30, 2010
  8. Jonathan NiederJun 30, 2010

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.