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

Re: git-add + git-reset --hard = Arrrggh!

From
Linus Torvalds <torvalds@osdl.org>
Date
May 17, 2006, 14:43 UTC
Message-ID
<Pine.LNX.4.64.0605170735540.10823@g5.osdl.org>
In-Reply-To
<20060517094526.GA8563@spearce.org>
On Wed, 17 May 2006, Shawn Pearce wrote:
Show 5 quoted lines
> 
> Oh, and I totally agree with that discussion about GIT not clobbering
> files the user is working on which the user can't easily recover.
> I just wish recovery from the above stupidity didn't require going
> through .git/objects looking for the newest file.  :-)
It doesn't.
Just do "git fsck-objects". It should have said
	dangling blob <sha1>
and you can just do
	git cat-file blob <sha1> > missing-file-name
and you're done.

That said, I think we should make everybody very aware of just how a _dangerous_ operation "git reset --hard" is. It does delete your work. On purpose. The fact that you can sometimes get it back doesn't change anything.

(And I say "sometimes", because you'll obviously have lost all the modifications that are only in your working tree - both to any added files and to any old-time files. That's the _point_ of it, after all).

The default for "git reset" is to _not_ do any modifications in the working tree. And there's a reason that's a default ;)

			Linus
Previous: Shawn PearceNext: Shawn Pearce
Message 2 of 3 in “git-add + git-reset --hard = Arrrggh!”
  1. Shawn PearceMay 17, 2006
  2. Linus TorvaldsMay 17, 2006
  3. Shawn PearceMay 17, 2006

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.