Krista's Coding Corner

12.05.2012

Different versions? -Commit a log!

Have you sometimes noticed the strange text “Commit log” after my posts? (Or if there has been a Freudian slip from my side “Comment log”). If you have, so probably you have also figured out that I put under that title changes I do after I have posted the text, just like some put the text “Edit:….” in forum posts.

Commit log is a list of changes with comments about the changes done to a program file. IF YOU DO ANY, AND I REALLY ANY VERSIONS OF YOUR PROGRAMS, USE COMMIT LOG. I actually got really upset to know that rare programmers use it. If you are a professional (or amateur doing things right), you use it. End of the discussion. (by the way, amateur always seems a bit like dismissive but think that the word comes from French word Amour, love <3. So, amateur actually means person who loves the thing he/she is doing).

But how to use Commit log? It is easier than you think; it doesn’t mean that you create an Excel-document where you have to remember to write about the changes you make, no no. It means using program called version control system. There are many of these programs but they can be divided into two: the ones that work with single server (every log goes into one place and you have to be connected to the server) and the ones that are distributed version controls (you don’t have to be connected to any server and if two people make modifications into same file, the program alerts about conflict that has to be solved later).

This might sound hard but it is the only way to really control programming projects that involve many people. Why then it is important also use this type of programs even if you do programs just for you and no-one else will even see them. Let me introduce more about the way version control programs work:

You have created the first file of your program. Then you have to ask the version control program to start tracking the file. This means the program saves the file somewhere hidden (it creates a COPY, you still have to save your files by yourself also) and starts to babysit the file: it is interested about changes happening to the file.

You then modify the file. Now, the version control doesn’t know about this unless you tell about it. You do the telling by doing a commit (= commit your changes to the version control). Depending on the program you use, you either do this via command line or right-clicking the file and choosing your version control program. Some other means may also exist.

Now the version control will ask comments about the change. It is really important that you do the commenting properly. If you don’t there is no use of the comment. The comments will help you later to see what has been done and why some changes have been done (but only if you write these to the log!).

The version control will save the changes. Normally it doesn’t save the whole new file, just the changes. It also creates commit log, where it saves your comments, links then to the changes and also saves some information about who did the commit and when.

If you later notice that some changes were stupid and you want to go back on time, you can: you just ask the version control to give you certain version and it does just that. And with your comments, it is easy to find the right version or spot in time (so, every time you do a change, do a commit! Don’t just collect a pile of changes and then commit as it kind of ruins the purpose of using version control).

This also means that your folders aren’t full of files titled as “program_65”, “program_new_ver”, “prog_changed_file_type” and so on. (just admit it, if you want to save some test cases of your program, you will at some point start to use awful file names that are incomprehensible later) With version control, you will just have one file title and that makes things so much easier.

And if you have others doing the program with you, you can keep track on what they have done and why and how their job is progressing.

Here are some version control programs for

single server solution: SVN (Subversion)

distributed solutions: Git and Mercurial.

PS. Why I use “commit log” here? So that the readers will know if there has come something new to the post, or if I have corrected some incorrect information and because then no-one has to wonder why some text isn’t saying the same thing that he remembers it used to. And because I hope it reminds people about using version control. :)

PPS. Don't use version control as a backup, it might not work as expected.

blog comments powered by Disqus