A common problem for programmers is making a change to a program and then it doesn't freaking work anymore. Panic sets in quickly. Maybe the change didn't work as expected. Maybe a typo or accidental random keypress. Or you spend a lot of time on a design change and decide the old design was better.
If the change was small no problem just change it back. If the changes were more extensive try to restore the editor backup copy. Still doesn't work. The file was saved several times. So try to restore from backups. What? I thought we backed that up? Now you are left to figure out what the heck was changed and claw back to where you started.
It was so painful you copy every program before changing it. Something like this:
These file copies litter your program directories like candy wrappers after Halloween.
I know what you're thinking. Let's put this under version control. Might as well use Git. Linus wrote Git in a weekend to handle the Linux kernel. Git should be able to handle my 70 line web clock application. Man Git. I read for 25 minutes. Holy nightmare Batman, how many commands does this thing have? 141.
git-reflog(1) Manage reflog information ...
At this point, I am radioactively pissed off. I call the US military. Hello? I need to speak with CENTCOM U.S. Army commander General Joseph Votel. Can I put you on hold? OK but this is important dammit. WHAT IN THE HELL DO YOU WANT? Sir, how about 2 commands. Code shows the snapshots. Code Comment
copies the stupid code. Codediff filename
compares the working file to the last snapshot. He hesitates, GET IT DONE RIGHT NOW. DO YOU UNDERSTAND ME? Yes Sir. Here it is.
One more thing. If you have a version control system. And if your program is included in version control. And if there is a snapshot before making changes. Then files can be recovered from version control. The key here is if you have a version control system and if the program is included in version control and if you took a snapshot. That's a long if statement.
The last program file restore on my systems was not from version control. It was from time machine. These backup systems automatically save every change to a file.
Backups are automatic and more reliable than version control. Consider using multiple backup systems and a version control system together to give yourself the best chance of recovering from that inevitable moment when a working program is not freaking working. Don't take my word for it. But when you are desperately trying to recover a program file with no backups and no snapshot, I will abuse you mercilessly.
dave@worldworstwriter.org 2024-10-26