{"thread":{"id":"50617","subject":"Prevent reset --hard from deleting everything if one doesn't have any commits yet","startedAt":"2019-02-28T21:43:22Z","lastAt":"2019-03-03T01:38:04Z","messageCount":5,"participants":["Manuel Guilamo","Johannes Sixt","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"370390","messageId":"15568DDA-F501-48C9-A1C0-97C72C29DA23@publicis.com.do","threadId":"50617","inReplyTo":null,"subject":"Prevent reset --hard from deleting everything if one doesn't have any commits yet","fromName":"Manuel Guilamo","fromEmail":"manuel.guilamo@publicis.com.do","sentAt":"2019-02-28T21:43:15Z","receivedAt":"2019-02-28T21:43:22Z","isPatch":false,"sender":{"key":"manuel.guilamo@publicis.com.do","avatar":null},"body":"I accidentally executed git reset —hard in a project that doesn’t have any commits yet. git erased everything, everything I’ve worked the past week, I believe this is not a desired behavior, considering I’m not able to undo that action, because git doesn’t have any history whatsoever."},{"id":"370409","messageId":"d1b34077-1c0e-7a2a-d2c7-da013dd56cd9@kdbg.org","threadId":"50617","inReplyTo":"15568DDA-F501-48C9-A1C0-97C72C29DA23@publicis.com.do","subject":"Re: Prevent reset --hard from deleting everything if one doesn't have any commits yet","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2019-03-01T06:56:00Z","receivedAt":"2019-03-01T06:56:06Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 28.02.19 um 22:43 schrieb Manuel Guilamo:\n> I accidentally executed git reset —hard in a project that doesn’t\n> have any commits yet. git erased everything, everything I’ve worked\n> the past week, I believe this is not a desired behavior, considering\n> I’m not able to undo that action, because git doesn’t have any\n> history whatsoever.\n\nI tested this, and it does not happen for me as long as I do not `git\nadd` anything.\n\nSo, I assume you did `git add` your content and then you did a `git\nreset --hard`. In that case, I'm afraid Git behaved as designed and\n\"doesn't have any commits\" is a red herring.\n\n-- Hannes\n"},{"id":"370415","messageId":"11C5FB4E-A4FF-430A-9305-E5BDA6A11049@publicis.com.do","threadId":"50617","inReplyTo":"d1b34077-1c0e-7a2a-d2c7-da013dd56cd9@kdbg.org","subject":"Re: Prevent reset --hard from deleting everything if one doesn't have any commits yet","fromName":"Manuel Guilamo","fromEmail":"manuel.guilamo@publicis.com.do","sentAt":"2019-03-01T13:46:20Z","receivedAt":"2019-03-01T13:46:24Z","isPatch":false,"sender":{"key":"manuel.guilamo@publicis.com.do","avatar":null},"body":"Oh yes... I did. Sigh\n\nRegardless,\n\nwouldn’t be nice to have a confirmation in cases like this? considering git isn’t only used by experts. It would’ve helped me A LOT, that’s for sure… and I’m 100% sure I won’t be that last person in the history of git that would suffer this.\n\nThank you for your quick reply.\n\n\n\n> On Mar 1, 2019, at 2:56 AM, Johannes Sixt <j6t@kdbg.org> wrote:\n> \n> Am 28.02.19 um 22:43 schrieb Manuel Guilamo:\n>> I accidentally executed git reset —hard in a project that doesn’t\n>> have any commits yet. git erased everything, everything I’ve worked\n>> the past week, I believe this is not a desired behavior, considering\n>> I’m not able to undo that action, because git doesn’t have any\n>> history whatsoever.\n> \n> I tested this, and it does not happen for me as long as I do not `git\n> add` anything.\n> \n> So, I assume you did `git add` your content and then you did a `git\n> reset --hard`. In that case, I'm afraid Git behaved as designed and\n> \"doesn't have any commits\" is a red herring.\n> \n> -- Hannes\n\n"},{"id":"370416","messageId":"20190301134759.GA13402@sigill.intra.peff.net","threadId":"50617","inReplyTo":"d1b34077-1c0e-7a2a-d2c7-da013dd56cd9@kdbg.org","subject":"Re: Prevent reset --hard from deleting everything if one doesn't have any commits yet","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-03-01T13:47:59Z","receivedAt":"2019-03-01T13:48:03Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Mar 01, 2019 at 07:56:00AM +0100, Johannes Sixt wrote:\n\n> Am 28.02.19 um 22:43 schrieb Manuel Guilamo:\n> > I accidentally executed git reset —hard in a project that doesn’t\n> > have any commits yet. git erased everything, everything I’ve worked\n> > the past week, I believe this is not a desired behavior, considering\n> > I’m not able to undo that action, because git doesn’t have any\n> > history whatsoever.\n> \n> I tested this, and it does not happen for me as long as I do not `git\n> add` anything.\n> \n> So, I assume you did `git add` your content and then you did a `git\n> reset --hard`. In that case, I'm afraid Git behaved as designed and\n> \"doesn't have any commits\" is a red herring.\n\nWouldn't that mean all of the file data is available in the object\ndatabase? Unfortunately without an index, there's nothing to mark which\nfile was which. But `git fsck --lost-found` should copy out all of the\nfile content into .git/lost-found.\n\n-Peff\n"},{"id":"370498","messageId":"xmqqa7ic3fgn.fsf@gitster-ct.c.googlers.com","threadId":"50617","inReplyTo":"20190301134759.GA13402@sigill.intra.peff.net","subject":"Re: Prevent reset --hard from deleting everything if one doesn't have any commits yet","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-03-03T01:38:00Z","receivedAt":"2019-03-03T01:38:04Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Wouldn't that mean all of the file data is available in the object\n> database? Unfortunately without an index, there's nothing to mark which\n> file was which. But `git fsck --lost-found` should copy out all of the\n> file content into .git/lost-found.\n\nIf we had a hierachically stored index that stores subdirectory\ncontents as a tree (or some tree-like things), \"fsck --lost-found\"\nwould have been able to recover even pathnames, but with the current\nflat index in a fresh directory without any commit, we'd get bunch\nof blobs without any clue as to where each of them goes.  It would\nbe far better than nothing, but leaves room for improvement.\n"}]}