Commit yourself to committing yourself
I came across an interesting anecdote today online. A programmer had recently switched code editors and was trying out features in this new editor. He started playing with the version control options, and he was prompted to stage his few thousand files not currently in version control. He clicked discard, and he accidentally deleted three months of work, permanently. Understandably, he was irate. He complained to the software company, writing angry posts everywhere he could online in an effort to get a response from the company. When they finally did respond, their response boiled down to this:
“Yes, this is unfortunate, and we regret this happening. But why you were operating on three months worth of code without any version control is the bigger question.”
This may seem like a snarky response of sorts, but it’s absolutely true. This programmer’s problem could have been completely avoided had he incrementally saved his work on an offsite backup or used revision control. What if the programmer’s computer had crashed, or someone spilled a drink on it? Are the couple seconds you save by not committing your work worth risking the loss of all of your data come some accidental catastrophe? The lesson here: Back up your work on at least one additional source.
Not only does this prevent against computer catastrophe, but it makes it a lot easier to revert to past versions of your code without having to CTRL + Z your day away. If you commit your work every time you write a line of working code, you can easily revert to the last working version of your code when you inevitably introduce a bug to your program.
Not only that, but committing can be done quite easily via a Git Bash terminal. After saving, head to your bash terminal, and perform these few tasks:
$ git status // shows all modified files since last commit
$ git add <file> // stage a particular file for commit
$ git commit // Opens the vim editor// In the vim editor, press 'I' to insert a commit message. Press
// ESC + wq to 'write' the commit and 'quit' the editor.//To backup this commit elsewhere:$ git push <destination> master // 'pushes' your latest commit to whichever backup location you specify.
You can revert to any of your prior commits by simply:
$ git revert <commit> //Reverts to the specified commitSimple as that.
Getting in the habit of committing your work and uploading it to a host like Github or BitBucket will prove to be invaluable the next time you introduce a bug to your code or run into technical trouble. Just ask the guy still re-typing that three months of code.
