Version control in Matlab using CVS

Posted: April 18, 2011 in HOW-TO's

Here follows a quick description of versioning in Matlab using the open source CVS package. Versioning is used to avoid confusion when multiple programmers work and use the same code. Essential for cross institutional collaboration. I chose CVS as it is freely available on both UNIX and MAC platforms, is well supported and is simple to use as part of the standard Matlab editor.

Step 1: Enable Source Control in Matlab
This is done through the Matlab preferences section. Under “General” click on “Source Control” and chose CVS.

Step 2: Setup your CVS environment variables

CVS uses an environment variable called $CVSROOT, to specify the location of the “CVS server”, ie. the master copy of the files that everyone “Checks out” and
“Checks in” again. Setting this is simple (See basic UNIX tutorials if you get stuck!):

First create a “cvsrep” directory. I suggest using a dropbox account to start of with. Make sure you all use the same file!
If you are using BASH, change your ~/.profile to inlcude:

# Set CVS enviroment
export CVSROOT=(The full path of your cvsrep directory in Dropbox)
export CVSEDITOR=emacs

To test, type:

>>echo $CVSROOT
>>(The full path of your cvsrep directory in Dropbox)

Step 3: Do an initial check-out of all the files.

>>cd (The full path of your cvsrep directory in Dropbox, then one of the individual directories.)

CVSROOT current matlab_toolbox max_tools pathtool

I want to work on a directory called ~/working_dir. So I change to my working_dir:
>> cd ~/working_dir

It is important that you are in the working directory! Now to checkout all the file, ie make copies of my cvsrep matlab_toolbox directory in my working_dir, I type:
>>cvs checkout matlab_toolbox

Do this for all the toolboxes you will edit. Then, open one of the .m files in your standard matlab editor. In the file menu, go to source control > check out.
From here, follow the standard MATLAB instructions. Every time you wish to change code, check it out and lock it! Then finally, when finished, check it in with a comment.

Let me know on how to make these instructions more accurate/user friendly!

Here are my sources:

CVS cheatsheet
Official MATLAB source control interface.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s