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

Re: Undo git-rm without commit?

From
Jeff King <peff@peff.net>
Date
Mar 26, 2008, 06:26 UTC
Message-ID
<20080326062635.GC26286@coredump.intra.peff.net>
In-Reply-To
<D6386C1A-92D3-4E11-8DE6-CC7553211A33@faithfulgeek.org>
On Wed, Mar 26, 2008 at 02:17:18AM -0400, Joe Fiorini wrote:
> I hadn't done a git-commit yet, but I used git-rm thinking it would  
> remove files that I had just added.  Instead, it deleted everything I had 
> added from the disk.  Is there a way to undo this?  I'm doubtful, but 
> would love to not have to rewrite what I was working on.

If by "added" you mean "git add"ed, then yes. The file is hashed and the blob is put in the object database during the add. Unfortunately, nothing actually _refers_ to it, so you will have to pick it out manually by its hash. Try:

  git fsck --lost-found
and then poke around .git/lost-found/other for your missing content.

As an aside, didn't git-rm warn you? While confirming that the command I was giving you was correct, I did this:

  git init
  echo content >file
  git add file
  git rm file
and got:
  error: 'file' has changes staged in the index
  (use --cached to keep the file, or -f to force removal)
-Peff
Previous: Mike HommeyNext: Joe Fiorini
Message 3 of 6 in “Undo git-rm without commit?”
  1. Joe FioriniMar 26, 2008
  2. Mike HommeyMar 26, 2008
  3. Jeff KingMar 26, 2008
  4. Joe FioriniMar 26, 2008
  5. Jeff KingMar 26, 2008
  6. Matthieu MoyMar 26, 2008

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.