{"thread":{"id":"4175","subject":"git-add + git-reset --hard = Arrrggh!","startedAt":"2006-05-17T09:45:26Z","lastAt":"2006-05-17T21:35:16Z","messageCount":3,"participants":["Shawn Pearce","Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"20120","messageId":"20060517094526.GA8563@spearce.org","threadId":"4175","inReplyTo":null,"subject":"git-add + git-reset --hard = Arrrggh!","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-05-17T09:45:26Z","receivedAt":"2006-05-17T09:45:26Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"After spending an hour writing and testing a new test case for GIT\nI do the foolish:\n\n\t$ git add t/t1400-update-ref.sh\n\t# Hmm, maybe I should amend this into the prior commit.\n\t$ git format-patch -o .. next\n\t$ git reset --hard\n\t$ git update-ref HEAD~1\n\t# Uhhohh...\n\t$ ls t/t1400-update-ref.sh\n\nAll I can say is I'm very happy that update-index does a lot more\nthan just update the index.  I was easily able to find the deleted\ntest by finding the most recently modified object in my .git/objects\ndirectory and pulling it back out with git cat-file.  :-)\n\nOh, and I totally agree with that discussion about GIT not clobbering\nfiles the user is working on which the user can't easily recover.\nI just wish recovery from the above stupidity didn't require going\nthrough .git/objects looking for the newest file.  :-)\n\nYes, I know that git reset --hard was brutal and yes, I didn't\nreally need to use git-update-ref when git-reset would have also\ndone the job for me.  Arrgh.  Its early and I wasn't thinking.\n\n-- \nShawn.\n"},{"id":"20146","messageId":"Pine.LNX.4.64.0605170735540.10823@g5.osdl.org","threadId":"4175","inReplyTo":"20060517094526.GA8563@spearce.org","subject":"Re: git-add + git-reset --hard = Arrrggh!","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-05-17T14:43:34Z","receivedAt":"2006-05-17T14:43:34Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Wed, 17 May 2006, Shawn Pearce wrote:\n> \n> Oh, and I totally agree with that discussion about GIT not clobbering\n> files the user is working on which the user can't easily recover.\n> I just wish recovery from the above stupidity didn't require going\n> through .git/objects looking for the newest file.  :-)\n\nIt doesn't.\n\nJust do \"git fsck-objects\". It should have said\n\n\tdangling blob <sha1>\n\nand you can just do\n\n\tgit cat-file blob <sha1> > missing-file-name\n\nand you're done.\n\nThat said, I think we should make everybody very aware of just how a \n_dangerous_ operation \"git reset --hard\" is. It does delete your work. On \npurpose. The fact that you can sometimes get it back doesn't change \nanything. \n\n(And I say \"sometimes\", because you'll obviously have lost all the \nmodifications that are only in your working tree - both to any added files \nand to any old-time files. That's the _point_ of it, after all).\n\nThe default for \"git reset\" is to _not_ do any modifications in the \nworking tree. And there's a reason that's a default ;)\n\n\t\t\tLinus\n"},{"id":"20186","messageId":"20060517213516.GA30313@spearce.org","threadId":"4175","inReplyTo":"81b0412b0605170722u15702301p2565e8ac29a5a0da@mail.gmail.com","subject":"Re: git-add + git-reset --hard = Arrrggh!","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-05-17T21:35:16Z","receivedAt":"2006-05-17T21:35:16Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Alex Riesen <raa.lkml@gmail.com> wrote:\n> On 5/17/06, Shawn Pearce <spearce@spearce.org> wrote:\n> >All I can say is I'm very happy that update-index does a lot more\n> >than just update the index.  I was easily able to find the deleted\n> >test by finding the most recently modified object in my .git/objects\n> >directory and pulling it back out with git cat-file.  :-)\n> >\n> \n> Maybe git-lost-found would help here?\n\nThanks!  I did that the hard way with git fsck-objects only to find\nI actually had a lot of dangling objects.  Luckily the most recent\none was the one I was looking for so a quick pipe through perl and\nls -t found it quite quickly.\n\nWhat would have really helped me was just using GIT properly\nrather than slamming something in fast with `git reset --hard`.\nSomehow that option has become part of my finger feel when using\nreset and that's just not right.  :-)\n\n-- \nShawn.\n"}]}