SVN - Version Control

This guide helps you Install and Setup SVN and use it to manage and access a repository.

So, what is SVN? Hmm... It's a version control system, where you'll forget all the pains of working-developing-non-working kinda codes of your application. You can have as many rollbacks of your code as possible, just at the whelm of a command.

Installation

fedora type : yum -y install subversion
ubuntu type : sudo apt-get install subversion
others : use your package manager and search, install subversion

Creating a repository and Initial import, checkout.

If all you want is to access a repository, skip this section. Others, let's carry on. This is the place (referred to as SVN root) where all your code and its various versions reside.

admin@tidbits# svnadmin create path/desired/svnroot_name
admin@tidbits# ls path/desired

all right? Now create the tree structure for your project. For example, see the following

admin@tidbits# mkdir temp_project_folder
admin@tidbits# mkdir temp_project_folder/branches
admin@tidbits# mkdir temp_project_folder/logs
admin@tidbits# mkdir temp_project_folder/trunk

Import that project directory to SVN root.

admin@tidbits# svn import /path/to/temp_project_folder file:///path/to/svn_root/project_name -m "Intial import"

this imports your project tree to a 'svn directory' named project_name in SVN root. '-m' is kinda needed for import as it is supposed to contain info about how this import is different from previous.  As this is our first import, we gave it as "Intial import". Ah!great going! I called it 'svn directory' as it couldn't be seen by normal ls. you could see it by..

admin@tidbits# svn ls file:///path/to/svn_root/
admin@tidbits# svn ls file:///path/to/svn_root/project_name

Now, we'll (neither SVN) have nothing to do with temp_project_folder in the future. We'll need to work on a copy imported from SVN root ONLY, which is called the working copy. Now, we have to make an initial check out before proceeding with making changes to project code. Go to path where you would like to have a copy of the project on which you'll be working.

admin@tidbits# svn checkout file:///path/to/svn_root/project_name project_name

Commits, Revisions, Versions

now, this folder, project_name, is your project folder. You should be working on this code to be able to commit the changes made. Say you have created src directory in that folder and has written a simple main.cpp.

admin@tidbits# cd project_name
admin@tidbits# mkdir src
admin@tidbits# touch src/main.cpp

now we'll commit the changes made. make sure you are in project_name folder. If we have created a new files/directories, we have to first add them to svn copy. If you are modifying the existing files, then just commit will be enough, no need to add them.

admin@tidbits# svn add src

this will add src directory and files in it. now commit the changes.

admin@tidbits# svn commit -m "src and main added"

if you have observed, this is our second commit. so, intuitively this is also called second revision. For example, if you want to have a look at the older revision, then you could import that by giving the following command. make sure you are in a correct directory of your choice.

admin@tidbits# svn checkout -r 1 file:///path/to/svn_root/project_name

this imports the earlier revision, which doesn't have src folder and main.cpp. To look at the log of what has all happened, you can use..

admin@tidbits# svn log

To get the information about the project, like its repository, revision imported etc,

admin@tidbits# svn info

this command can also take directory/file as argument to give info of that specific component.

To create a version (note that revision is different from version), create tags directory and 'svn copy' folder that contains the code into tags directory with appropriate name. say trunk is the source code folder,

admin@tidbits# svn create tags
admin@tidbits# svn copy trunk tags/first-version
admin@tidbits# svn commit -m "this is the first version of some crap"

To checkout this version,

admin@tidbits# svn checkout file:///path/to/svn_root/project_name/tags/first-version

If you want to rename any of existing files or folders, use svn rename,

admin@tidbits# svn rename trunk src

this renames trunk folder to src. don't forget to commit, if needed.

So, thats it! Oh OK, this is not all of it, SVN has much more than what I just covered. But this should be enough for what most people need.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options