Git is INCREDIBLY dangerous

I was stepping through a tutorial on how to stage items before committing and noticed that I added a folder full of stuff that didn’t need to be in the source tree. I followed the instructions on how to remove items (git rm HEAD file), ran a git status and noticed the folder was still in the list of staged items. I tried a few more times with the same result. I then found the git reset -hard command, ran that, and poof. A months worth of work was not only removed from the staging area, but physically deleted from my hard drive.
Why is this allowed to happen? I wanted to remove items from the staging area, not my hard drive, so why does git think it owns things not in the staging area? And is there any possible way to get that month’s worth of work back?

Thanks for any help

1 Like

I don’t want to seem rude, but I think that before executing a command you should know the result. It’s like run

sudo rm -rf /

on Linux, you dont do that if you know the result. Every powerfull commands are dangerous if you didnt know what it does.

Fair enough, but I think its not too much to ask that a third party development tool, like git, should not use the exact same command to edit their custom data structure that the OS uses to delete files from a users computer. If they want to allow adding and removing file references from a custom data structure, they should invent commands that have no possibility of deleting the files referenced within that data structure.
Everyone is a beginner sometime and expecting beginners to be experts in all things Unix to even attempt a tutorial is a bit much.

1 Like

Using  git reflog ( you can pretty much recover anything.

1 Like