Only run reset hard after committing desired files

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the git category.

Last Updated: 2021-05-15

Late one night, after coding too much, I ran git reset ---hard somewhat thoughtlessly, assuming after a cursory glance at git gui that this command would only remove rubbish I didn't want.

I was wrong. I lost a long (and annoying to write) integration test and had to spend an hour writing it again.

Lessons

Carefully commit all desired code in git before going near git reset --hard. I.e. Commit everything good (rather than simply eyeballing) before resetting

Double-check you will be doing the right thing with git reset --hard since you cannot recover that data if you make a mistake.