Geeks With Blogs
Code.Blog Code Talk for the Game Developer

Subversion (SVN) is a popular tool used by many development teams as their primary way of versioning their code.  Here are some of the basics to SVN.

Possibly one of SVN's best aspects is the ability to work on a shared code base.  This shared code base is called the Trunk.  This is typically where the full, buildable code resides.  It may depend on your team, but this code may be the code you work on daily and commit to.

This leads into the idea of commits and updates.  To illustrate this, let's imagine that you started a small project and had a decent amount of code developed by yourself.  Recently, you've added members to your team and need to provide that code as the shared base (the Trunk).  You've got yourself a server and through the advances in technology have SVN pre-installed and waiting to grab your code.  After opening up your IDE of choice, you would create a Trunk based of the code you have on your machine.  The code you have on your harddrive that is not shared is called your Local Version, or Working Version.  SVN happily creates a Trunk and is ready to give your team the base code.  Now, your team will perform an Update to grab the latest version of the code.  An Update will bring the latest code from the repository to your Local Version.  After that point, your team is able to work on their code on their own machines and work on different parts of the project.  Each person will work on different files and have to submit their changes to the Trunk to create a new, updated version of the code base.  To Commit, is the process of uploading your local changes to the code base to use the newly written code.  When you created the trunk, you Commited your local 'changes' (the change was from nothing to your project) to the Trunk.

Commits and Updates are wonderful, but lead to a major issue.  Let's assume two team members are working on the same file, HelloWorld.txt.  Both team members come into work and grab the latest copy of that file within minutes and begin working on it.  Team Member 1 types the words 'I Love SVN!' into the file and Commits the file.  Meanwhile, Team Member 2 types the words, 'SVN Rules!' into the file and tries to Commit the file.  Suddenly we've hit a snag because Team Member 2 wants to put his changes into the base code but hasn't Updated since Team Member 1 commited his file.  This problem of being 'out-of-sync' is resolved via a process known as a Merge.  A Merge is when a developer looks at the changes to his/her Local Version of a file and the changes made to a Trunk file that hasn't been Updated on the Local Version, and fixes the synchronization issue by ammending the code to include both updates or one of the updates.  Here are Team Member 2's possible merge solutions:

  • Override and Update: In this case, the Local Version of the file is discarded and the Trunk code overwrites everything.  HelloWorld.txt would contain the text 'I Love SVN!' from Team Member 1, but not the text 'SVN Rules!' from Team Member 2.
  • Override and Commit: This is similar to Override and Update, but the Trunk code is overwritten with the Local Version.  HelloWorld.txt would not contain the text 'I Love SVN!' from Team Member 1, but would contain the text 'SVN Rules!' from Team Member 2.
  • Merge Changes: In this solution, both changes are merged into Team Member 2's Local Version and (s)he is able to commit the file and overwrite the Trunk file.  HelloWorld.txt would contain both pieces of text from Team Member 1 and Team Member 2.

During the process of Commiting, Updating, and Merging, the code base can change quite drastically.  As they teach in most computer classes, backing up your data is key to continuing a project without major losses.  SVN handily provides a way to backup your code via Tags.  A Tag is a snapshot of your code at a given time.  It is similar to a Trunk but it is assumed a Tag will not change in the future.  This is useful if a situation arises where it is necessary to revert your code base to a prior state.  In larger environments, Tags are created with each build.

Many projects typically require temporary code written during development in order to test specific issues without a fully functioning product.  Here's an example, assume that project we talked about earlier needs to test a function that calculates the amount of times a number can be divided by 2.  In the final product, that value will be provided by an external system, but currently this system is not implemented.  The plan is to develop a temporary text field that will accept a value and run the function.  In the final product, there will be only a label with the value in it, not a text box.  From what we've been told about SVN up to this point, we would go into the base code, insert our temporary field, and test the function.  This is somewhat practical with a single field, but now let's assume there are 100 fields like this.  Obviously, it would be a massive headache to Update, write the changes, Commit, and in the future have to Update, revert the changes, and Commit.  Sure you could use a Tag, but why create a backup of code that is temporary? 

Introducing Branches, a seperate Trunk-style project used for work on a project similar to this.    If this team hires a new developer and wants to slowly introduce him to the project but doesn't want him developing on the Trunk, what can they do?  Create a Branch for him/her to work on!  Branches can be created from existing code bases, including the Trunk and Tags.  Even better, you can Merge between a Branch and the Trunk to bring in changes from the temporary project that need to be implemented into the code base.

This is a lot of information, and is really basic when talking about SVN, but very helpful when someone asks you, "Are we going to make a Tag of the Branch before Merging into the Trunk?"  Now, go say that to everyone you meet and see if they know their SVN.

Posted on Wednesday, September 30, 2009 3:59 AM Tutorials | Back to top


Comments on this post: Intro to SVN: Trunk, Tags, and Branches

# re: Intro to SVN: Trunk, Tags, and Branches
Requesting Gravatar...
svn subverson control system
Left by sunil on Dec 30, 2009 1:06 AM

# re: Intro to SVN: Trunk, Tags, and Branches
Requesting Gravatar...
Thank you so much for this info!!!
Left by Nilesh on Feb 13, 2010 6:39 AM

# re: Intro to SVN: Trunk, Tags, and Branches
Requesting Gravatar...
Very brilliant. Well explained. Thank you.
Left by Zelalem on Apr 27, 2011 3:48 AM

# re: Intro to SVN: Trunk, Tags, and Branches
Requesting Gravatar...
Very good, I am a monkey and even I understand this!
Left by OooOoEEeOo on Mar 02, 2012 8:29 AM

# re: Intro to SVN: Trunk, Tags, and Branches
Requesting Gravatar...
SVN is still the best source control and versioning system on earth!
Left by Harald-René Flasch on Apr 04, 2012 7:33 AM

# re: Intro to SVN: Trunk, Tags, and Branches
Requesting Gravatar...
A good help to understand concept of branch, tag, trunk
Left by UAK on Jun 04, 2012 2:12 AM

# re: Intro to SVN: Trunk, Tags, and Branches
Requesting Gravatar...
VERRRRRRYYYY HELPPFULL!!! So happy i found this article...
Left by ace_on on Sep 25, 2012 7:32 AM

# re: Intro to SVN: Trunk, Tags, and Branches
Requesting Gravatar...
nice xplanation
Left by babu on Dec 28, 2012 6:33 AM

# re: Intro to SVN: Trunk, Tags, and Branches
Requesting Gravatar...
Hey Thanks for Info..
1] you have mentioned "Tag is useful if a situation arises where it is necessary to revert your code base to a prior state" ...
2] I want know the exact procedure.. How we can revert from Tag..
SVN commant or what? Please provide the solution.
Left by Nilesh Balgude on Feb 07, 2013 11:30 PM

# re: Intro to SVN: Trunk, Tags, and Branches
Requesting Gravatar...
Fantastic article to understand difference between trunk, branch and tag in svn. I love the way you explained them via picture, must read for any programmer.
Left by Gopal on Jul 31, 2014 11:22 AM

Your comment:
 (will show your gravatar)


Copyright © Matthew Christian | Powered by: GeeksWithBlogs.net