{"thread":{"id":"12871","subject":"Undo git-rm without commit?","startedAt":"2008-03-26T06:17:18Z","lastAt":"2008-03-26T09:48:03Z","messageCount":6,"participants":["Joe Fiorini","Mike Hommey","Jeff King","Matthieu Moy"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"73113","messageId":"D6386C1A-92D3-4E11-8DE6-CC7553211A33@faithfulgeek.org","threadId":"12871","inReplyTo":null,"subject":"Undo git-rm without commit?","fromName":"Joe Fiorini","fromEmail":"joe@faithfulgeek.org","sentAt":"2008-03-26T06:17:18Z","receivedAt":"2008-03-26T06:17:18Z","isPatch":false,"sender":{"key":"joe@faithfulgeek.org","avatar":null},"body":"I hadn't done a git-commit yet, but I used git-rm thinking it would  \nremove files that I had just added.  Instead, it deleted everything I  \nhad added from the disk.  Is there a way to undo this?  I'm doubtful,  \nbut would love to not have to rewrite what I was working on.\n\nThanks!\nJoe\n"},{"id":"73116","messageId":"20080326062422.GA18856@glandium.org","threadId":"12871","inReplyTo":"D6386C1A-92D3-4E11-8DE6-CC7553211A33@faithfulgeek.org","subject":"Re: Undo git-rm without commit?","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2008-03-26T06:24:22Z","receivedAt":"2008-03-26T06:24:22Z","isPatch":false,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"On Wed, Mar 26, 2008 at 02:17:18AM -0400, Joe Fiorini wrote:\n> I hadn't done a git-commit yet, but I used git-rm thinking it would  \n> remove files that I had just added.  Instead, it deleted everything I  \n> had added from the disk.  Is there a way to undo this?  I'm doubtful,  \n> but would love to not have to rewrite what I was working on.\n\nYour best take would be to take a look at the unreachable loose objects\nin your repository. One way to have a list of them would be to do a\ngit prune -n. Then you can look at the contents of each blob in those\nwith either git cat-file -p $sha1, or git show $sha1.\n\nMike\n\nPS: What you wanted to use is git reset, not git rm.\n"},{"id":"73117","messageId":"20080326062635.GC26286@coredump.intra.peff.net","threadId":"12871","inReplyTo":"D6386C1A-92D3-4E11-8DE6-CC7553211A33@faithfulgeek.org","subject":"Re: Undo git-rm without commit?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-03-26T06:26:35Z","receivedAt":"2008-03-26T06:26:35Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Mar 26, 2008 at 02:17:18AM -0400, Joe Fiorini wrote:\n\n> I hadn't done a git-commit yet, but I used git-rm thinking it would  \n> remove files that I had just added.  Instead, it deleted everything I had \n> added from the disk.  Is there a way to undo this?  I'm doubtful, but \n> would love to not have to rewrite what I was working on.\n\nIf by \"added\" you mean \"git add\"ed, then yes. The file is hashed and the\nblob is put in the object database during the add. Unfortunately,\nnothing actually _refers_ to it, so you will have to pick it out\nmanually by its hash. Try:\n\n  git fsck --lost-found\n\nand then poke around .git/lost-found/other for your missing content.\n\nAs an aside, didn't git-rm warn you? While confirming that the command I\nwas giving you was correct, I did this:\n\n  git init\n  echo content >file\n  git add file\n  git rm file\n\nand got:\n\n  error: 'file' has changes staged in the index\n  (use --cached to keep the file, or -f to force removal)\n\n-Peff\n"},{"id":"73119","messageId":"0535D2B4-0C4A-40D0-879A-7E0C5B3B48E4@faithfulgeek.org","threadId":"12871","inReplyTo":"20080326062635.GC26286@coredump.intra.peff.net","subject":"Re: Undo git-rm without commit?","fromName":"Joe Fiorini","fromEmail":"joe@faithfulgeek.org","sentAt":"2008-03-26T06:38:42Z","receivedAt":"2008-03-26T06:38:42Z","isPatch":false,"sender":{"key":"joe@faithfulgeek.org","avatar":null},"body":"Yeah, it warned me, I wasn't being careful enough.  I guess I didn't  \nthink it would remove from the working tree, just the repository.  My  \nerr for not reading the docs until _after_ the mistake.  Live &  \nlearn.  Thanks for the help, opening lost-found/other in TextMate  \nsolved my problem quickly!\n\nThanks again!\nJoe\n\nOn Mar 26, 2008, at 2:26 AM, Jeff King wrote:\n\n> On Wed, Mar 26, 2008 at 02:17:18AM -0400, Joe Fiorini wrote:\n>\n>> I hadn't done a git-commit yet, but I used git-rm thinking it would\n>> remove files that I had just added.  Instead, it deleted everything  \n>> I had\n>> added from the disk.  Is there a way to undo this?  I'm doubtful, but\n>> would love to not have to rewrite what I was working on.\n>\n> If by \"added\" you mean \"git add\"ed, then yes. The file is hashed and  \n> the\n> blob is put in the object database during the add. Unfortunately,\n> nothing actually _refers_ to it, so you will have to pick it out\n> manually by its hash. Try:\n>\n>  git fsck --lost-found\n>\n> and then poke around .git/lost-found/other for your missing content.\n>\n> As an aside, didn't git-rm warn you? While confirming that the  \n> command I\n> was giving you was correct, I did this:\n>\n>  git init\n>  echo content >file\n>  git add file\n>  git rm file\n>\n> and got:\n>\n>  error: 'file' has changes staged in the index\n>  (use --cached to keep the file, or -f to force removal)\n>\n> -Peff\n"},{"id":"73118","messageId":"20080326063951.GA26859@coredump.intra.peff.net","threadId":"12871","inReplyTo":"0535D2B4-0C4A-40D0-879A-7E0C5B3B48E4@faithfulgeek.org","subject":"Re: Undo git-rm without commit?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-03-26T06:39:52Z","receivedAt":"2008-03-26T06:39:52Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Mar 26, 2008 at 02:38:42AM -0400, Joe Fiorini wrote:\n\n> Yeah, it warned me, I wasn't being careful enough.  I guess I didn't  \n> think it would remove from the working tree, just the repository.  My err \n> for not reading the docs until _after_ the mistake.  Live & learn.  Thanks \n> for the help, opening lost-found/other in TextMate solved my problem \n> quickly!\n\nOK, good. Just making sure there wasn't a bug in rm. ;)\n\n-Peff\n"},{"id":"73133","messageId":"vpqve3995po.fsf@bauges.imag.fr","threadId":"12871","inReplyTo":"0535D2B4-0C4A-40D0-879A-7E0C5B3B48E4@faithfulgeek.org","subject":"Re: Undo git-rm without commit?","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2008-03-26T09:48:03Z","receivedAt":"2008-03-26T09:48:03Z","isPatch":false,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"Joe Fiorini <joe@faithfulgeek.org> writes:\n\n> Yeah, it warned me, I wasn't being careful enough.  I guess I didn't\n> think it would remove from the working tree, just the repository.  My\n> err for not reading the docs until _after_ the mistake.\n\nReading the error message would have done it also :-\\.\n\n>>  error: 'file' has changes staged in the index\n>>  (use --cached to keep the file, or -f to force removal)\n         ^^^^^^^^^^^^^^^^^^^^^^^^^\n\nGood luck with lost+found, still !\n\n-- \nMatthieu\n"}]}