In Loving Memory - my snake program

A short tragic story about how I deleted all the code in a project while trying to back it up with git.

by spitemim, 2022-05-15


Yesterday, I decided to write a snake program in C just for fun. I used a linked list to represent the parts of the snake, and used ncurses to draw the graphics. I finished the game within a day to the point where I was pretty happy with it, and naturally I decided to post it to GitHub.

I had run git add . before editing my .gitignore to ignore my program’s binary. Before comitting, I wanted to unstage the binary. Not entirely caught up with my git knowledge, I tried to run git unstage *. Didn’t work.

I eventually found out that you can unstage files by running git rm --cached. Notice the flag at the end? --cached. In my infinite wisdom, I forgot to add that.

Long story short, I ran git rm -rf *. Not yet aware of my mistake, I ran ls and realized what I’d done: NO FILES existed in the directory. I tried every trick in the book to coax git into somehow restoring my project, but alas, I had not made the first commit yet. I had no luck.

The sad thing is, I was totally in the zone when I wrote that program. The code flowed smoothly and just seemed to work. Even if it wasn’t the most readable thing in the world, in the moment, it felt artisan-crafted. And now it’s gone.

From this point on, every program I write will be TWICE as great as the snake program lost to the void.

Godspeed, my fellow programmers. May your backups be reliable and your pointers always be != NULL.