Stupid Mistake and How to recover from git reset hard

Post pandemic, I had a desktop and laptop assigned to me. I always preferred the desktop as laptop seemed too slow compared to desktop.

But in mid-March 2020, everything changed, the desktop was left alone in office and the neglected laptop become the primary workhorse.

While migrating my work from desktop to laptop, I dumped few things on my desktop and as i was in the habit of have a version-controlled desktop,

I did these two commands.

git init
git add *

As soon as the command completed, I realized, I do not want to git control some of the files, so instinctually did this.

git reset --hard

This deleted all the files on the desktop. At this I realized my stupid mistake. The quarter worth of work was deleted from the desktop. I checked recycle bin and there was nothing.

After a frantic and panic driven hour, finally did find the solution and got back my accidentally deleted files


git fsck --lost-found

Now go to .git/lost-found folder and you should see the files, but they will be hashed. Need to save them individually

So next day was spent looking the lost-found folder and restoring the files, which essentially meant renaming the folder and files and getting them out of this lost-found folder.

Glad to have found this, otherwise, the first few weeks of the pandemic were destined to be recreating the work done in January and February.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s