Re: Prevent reset --hard from deleting everything if one doesn't have any commits yet
- From
Jeff King <peff@peff.net>
- Date
- Mar 1, 2019, 13:47 UTC
- Message-ID
- <20190301134759.GA13402@sigill.intra.peff.net>
- In-Reply-To
- <d1b34077-1c0e-7a2a-d2c7-da013dd56cd9@kdbg.org>
On Fri, Mar 01, 2019 at 07:56:00AM +0100, Johannes Sixt wrote:
Show 13 quoted lines
> Am 28.02.19 um 22:43 schrieb Manuel Guilamo: > > 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. > > I tested this, and it does not happen for me as long as I do not `git > add` anything. > > So, I assume you did `git add` your content and then you did a `git > reset --hard`. In that case, I'm afraid Git behaved as designed and > "doesn't have any commits" is a red herring.
Wouldn't that mean all of the file data is available in the object database? Unfortunately without an index, there's nothing to mark which file was which. But `git fsck --lost-found` should copy out all of the file content into .git/lost-found.
-Peff