Friday, October 25, 2013

Personal Version Control on the cheap (FREE!)

I've always been a fan of version control for my own documents. I can't even begin to tell you how many times I have edited and saved something (code, word documents, really anything) then went back to look for something that I in my infinite wisdom decided to delete because "it would never be needed". Well guess what? I was wrong.

Recently, I've been working much more on scripts mainly TSQL but also find myself building support documents, random documentation, spreadsheets for automation, etc...basically things that change periodically and that I would like to keep previous versions just in case :)

There are all kinds of version control software but I've been a fan of Tortoise SVN in the past and still am. It integrates well with Windows, yes I'm a Windows user; version control isn't only for Linux. TortoiseSVN is actually an Apache Subversion client. While this implies you need a server and really could have one running Subversion, you can also utilize Tortoise SVN to create a local Subversion repository. Note: This means if you care about your repository you will need to back it up.

Here are the steps to create yourself a local version controlled folder:

1. Download and Install the latest version of TortoiseSVN; this will be a next --> next --> Finish type install.

2. Create a new folder that you would like to be the root of your repository. For our example we'll call it C:\SVNRepository.

3. Right Click the folder you created (C:\SVNRepository), you should see a TortoiseSVN menu. Mouseover that menu and you will have numerous options. Choose "Create Repository Here"

4. You will receive a window to confirm. Here you could create the default folder structure of trunk/branch/tags. But I don't and unless you are well versed in using these different constructs I think it just becomes confusing. So, I recommend hitting Ok at this point or go read up on the trunk/branch/tags construct and see if it is something you'd like to try out. This isn't a life or death decision, these are basically just folders and if you end up not liking them well just delete them.

5. Assuming you eventually hit Ok, your folder will now have a different icon that is good. Create a folder in Windows that will serve as your working directory. For our example we'll call it C:\WorkingDirectory.

6. Right Click on C:\WorkingDirectory --> Left Click "SVN Checkout..."

7. You should now have a "Checkout" window open. For "URL of repository:" enter "file:///C:/SVNRepository". The "Checkout directory" should already be set to C:\WorkingDirectory. Click Ok.

8. Double click C:\WorkingDirectory, you now have an empty folder. You can create folders and files in here as you wish. Create something, anything for now.

9. So you've created something in step 8 and your folder is no longer empty. But it is not saved to the repository yet. Right click on C:\WorkingDirectory --> Left click "SVN Commit"

10. You will now have a "Commit" window. It will show you all the changes you have made and a comment box, you should only see new things that say non-versioned at this point and you can add a comment as appropriate. Click the check boxes next to the items you want to save to the repository and click ok. Click Ok again.

11. If you haven't already done so create a document or copy one over, make sure to commit changes as in step 9. You can also right click on a specific file and commit it rather than the entire structure. Modify this file a few times and commit so that we have some changes to revert or compare.

12. Now you should have one file that has multiple revisions, first make sure you left click the file --> then right click on this file --> Mouseover TortoiseSVN --> Left Click "Show Log".

13. You will now have a "Log Messages" window open and you can click on each version of your file. Right clicking any of these versions gives you a plethora of choices including comparing to current version, comparing to a previous version, reverting, saving off a revision as something else, etc...play around and see what you can do.

This is by no means an extensive tutorial on using TortoiseSVN or Apache Subversion but rather a quick and dirty setup guide and just enough to get you going and playing. There are other features you could use such as add (if you have a new file or folder that you create in the structure) this has the advantage of showing you that you have a new file that now doesn't match the repository without committing. You can also import files/folders from an existing location. There are tons of things you can do but you can read more about that at the Apache Subversion Documentation and TortoiseSVN Support websites. You may even find you want or need to setup an Apache Subversion server if you want to use it for more than your personal repository.

No comments: