decoration left 1
decoration left 2
decoration rigth

Show/Hide search bar
black cat logo variable logo
[07 Nov 2012]

SVN basics

You can use SVN (subversion) to manage different versions of source code or other types of files in such a way that allows you to work together on same project with a lot of other developers. Or you can just use it for yourself, to control your progress and to have possibility to return to previous versions of your project.

SVN server is usually located in the Web, but if you want to use SVN on your computer for personal purposes, install SVN server like Apache subversion and client like Tortoise SVN. Such setup doesn't allow you to restore the files if your HDD will break, but it's useful for homemade projects or when you don't have dedicated SVN server. Also you can use only server without client, but then you will work only with console and it's not as easy and straightforward as GUI. Tortoise SVN client provides pretty GUI to help you. It will add state indicators to files and folders, and additional commands to context menu.

Terminology related to SVN
  • Repository folder where database with all versions of code is stored.
  • Working copy folder that is linked to repository and contains your current version of code.
  • Revision - version of code saved in repository.
    Three steps to begin

    First of all, create folder for all repositories, and then subfolder for repository of your project. Then, right click on that subfolder -> TortoiseSVN -> Create repository here. This subfolder will contain database of all versions, source code, images etc. Or you can use console command for this: svnadmin create C:/repositories/repositoryForProject

    Then you can import your project to repository. This will copy whole structure of your unversioned project to repository. You can do it with Import command from context menu (context menu of repository folder). Now your project is in repository and is at revision 1. Or import project to repository by following command from console: svn import -m --force-log C:/project file:///C:/repositories/repositoryForProject

    Now you should select folder for your development, like C:/projectDev. This folder is emply, but we will fix that. Right click on new folder and from context menu select SVN Checkout command. In path field specify your repository, like file:///C:/repositories/repositoryForProject. Press on OK button, your project will be coppied from repository to your development folder.

    Work with SVN

    Now you have to modify your code in development folder (C:/projectDev). When you will be happy with changes and think that it's good idea to save them as individual version, then you have to commit your code. This means that all changes from development folder will be sent to repository as new revision. You can perform commit through context menu Commit command. Each commit is atomic transaction and creates one new revision.

    Now, lets imagine that you work with other developers. And someone have performed commit of his code. But this new code won't be visible for you until you perform Update command from context menu. This brings your working copy of code up to date.

    During your commit there may be conflicts. Conflict means that part of your changes overlap with changes of another user. For each file with conflicts select Edit Conflicts, analyze conflicted parts of the code, properly modify code and then save it. If you sure that conflict is removed then select Resolve Conflict action.

    There're a lot of other helpful commands. Here are some of them:

  • Diff - for files. Shows your modifications after last update.
  • Diff with previous version - shows difference between previous revision and your current version.
  • Add - adds new files and folder to version control.
  • Revert - revert manual changes to initial state. You can find reverted files in recycle bin.
  • Revert to revision - restore state of specified revision.
  • Show log - shows a list of revisions that are associated with selected file or folder.
  • Compare with base - shows local changes that you have made.
  • Export - exports files to another folder without version control information.
  • Ignore - don't commit selected files and folders. You can also exclude specific file types.
  • RepoBrowser - repository explorer, shows structure of folders in repository.
    How SNV works?

    Subversion at its core is a repository. Information is stored as hierarchy of files or folders. Repository is a kind of server that remembers any change to files. There is possibility to perform work with lock-modify-unlock sequence of actions. When file is locked, only locker can modify it. But such behavior stalls development of project. SVN uses copy-modify-merge sequence. This leads to some conflicts between commits of multiple users, but usually these conflicts can be easily resolved.

    Structure of repository folders

    Usually, repositories of commercial products have strage layout of folders. There're trunk, branches and tags folders. They have following purpose:

  • /trunk - main line of development, usually it's stable version for release.
  • /branches - code that contains major changes but is still under development or tests, and will be merged into trunk folder.
  • /tags - contains copies of release versions.

    But for home projects you can import your projects into repository as is.

    SVN in Qt

    Qt has built-in support of different version control systems. Subversion is among them but I think that it's easier to use TortoiseSVN.

    First of all, you have to setup Qt to work with proper subversion server. Go to Tools -> Options -> Version Control -> Subversion. Locate svn.exe of your subversion server and fill authentication data.

    Now you can import project from repository. Go to File -> New Project ->Import Project -> Subversion Checkout. Select repository like file:///C:/repositories/repositoryForProject and folder for development.

    And finally you can find different SVN commands here: Tools -> subversion -> XXX.

  • Sun and Black Cat- Igor Dykhta (igor dykhta email) 2007-2014