Version Control with Subversion

What is Subversion?

Subversion is a centralized system for sharing information. At its core is a repository, which is a central store of data.

Install Subversion

You have to install two things:

  1. Subversion Server (Repository)
  2. Subversion Client (Used to connect to the repository)

Subversion Server Installation and configuration:

Download the latest SVN server from http://subversion.tigris.org/project_packages.html

I have downloaded Subversion Server under Windows

http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91

Install SVN server.

After complete the installation, you have to set some environment variables:

Subversion binaries to the path environment variable for the machine.

SVN_EDITOR, set to the text editor of your choice. I used c:\windows\notepad.exe

Create a Repository
Create repository folders in your hard drive, I have created
c:\svn_repository\
Open command prompt and type:
svnadmin create "c:\svn_repository"

Now, you have a repository and you can start using it.
But first we have to configure SVN server, to let any one in your 
network to use this repository.
Navigate to the folder we just created. Within that folder, uncomment the
 following lines in the c:/svn_repository/conf/svnserve.conf file:

anon-access = read
Any user who is not authenticated user can read
auth-access = write
Any authenticated user can write
password-db = passwd
The user names and passwords are in the default file 
c:/svn_repository/conf/passwdc:/svn_repository/conf/passwd
					

sami.alsayyed = sami123
User name: sami.alsayyed
Password: sami123
Start SVN server by executing this command:
svnserve --daemon --root "C:\svn_repository"

Keep this screen and open another command prompt window.
Install SVN as windows service
To start SVN server as windows service, just execute this command
sc create svn binpath= "C:\Program Files\Subversion\bin\svnserve.exe --service -r 
C:\svn_repository" displayname= "Subversion Server" depend= Tcpip start= auto
After that you should see the new service "Subversion Server"

Now any one in your network can see your repository and use it.
Test the new service by listing all the files in the repository:

Create a new project in the repository by executing this command:
svn mkdir svn://localhost/myproject

At this point, Notepad should launch:

Enter any comment you want at the top of the file, then save and exit.
You'll now be prompted for credentials. In my case I was prompted for the administrator credentials as well:
Authentication realm:  0f1a8b11-d50b-344d-9dc7-0d9ba12e22df
Password for 'Administrator': *********
Authentication realm:  0f1a8b11-d50b-344d-9dc7-0d9ba12e22df
Username: sami.alsayyed
Password for 'sami.alsayyed': ************
Committed revision 1.
				
Congratulations! You just checked a change into Subversion!
Install SVN Client "TortoiseSVN"
				
Download the latest TortoiseSVN from here: http://tortoisesvn.net/downloads				
Run the TortoiseSVN installer. It will tell you to restart, but you don't need to.

You have to install this software in all clients, to let them access your 
SVN repository and use it.Assuming you are some of the clients, after 
installation complete you have to check out the project in the repository.
Create a project folder somewhere on your hard drive. 
Right click in that folder and select "SVN Checkout..."

svn://localhost/
is the URL for the repository, if you are setting in a different 
machine you have to write the computer name or IP address
Click ok. After that you will see this window:

Click ok, you have successfully checked out the projects inside the 
repository first project we have added lately to the repository.

Try to add some document to this folder "myproject"
Create a new file in that directory. Right click the file and select "TortoiseSVN, Add"

Click ok.

Click ok

The file hasn't actually been checked in yet. 
Subversion batches any changes and commits them as one atomic operation.
To send all your changes to the server, right click and select "SVN Commit":

Type you comment and press ok

You have to write your user name and password to commit this file, you should be authenticated user.	
And we're done! You now have a networked Subversion server and client set up on your machine
Note that the default port for svnserve is 3690.
Some quick commands
					
create a new repository
svnadmin create c:/svn_repository
Import files to thr repository
svn import C:\from_file svn://localhost/
Take a backup to dumpfile
svnadmin dump c:/svn_repository > dumpfile
Load the dumpfile
svnadmin load c:/svn_repository < dumpfile
Take a back up
svnadmin hotcopy c:/svn_repository c:/backup_svn_repository
Start SVN Server
svnserve --daemon --root "C:\svn_repository"
Create SVN Windows service

sc create svn binpath= "C:\Program Files\Subversion\bin\svnserve.exe
 --service -r C:\svn_repository" displayname= "Subversion Server" 
depend= Tcpip start= auto

Create a new folder in the repository
svn mkdir svn://localhost/myproject
See the log
svn log svn://localhost/
Checkout
svn checkout svn://localhost/ c:\myproj
Adding files to repository
svn add a-file-I-added.txt
Changed

with the status

svn st
Commit your changes
svn ci -m "Put a comment here, 
or an editor opens to get one."
Files can be deleted with the remove (or rm) command, and moved or renamed with the move (mv) command:
svn rm unwanted-file.txt
svn mv badname.txt goodname.txt
Update the changes
svn up

References

Subversion on Windows quick start

http://nedbatchelder.com/text/quicksvn.html
SVN Tips - svn_load_dirs Vendor Branch

http://docs.ofbiz.org/display/OFBIZ/SVN+Tips+-+svn_load_dirs+Vendor+Branch
Subversion branching quick start

http://nedbatchelder.com/text/quicksvnbranch.html
Subversion - A Quick Tutorial

http://aymanh.com/subversion-a-quick-tutorial
Version Control with Subversion

http://svnbook.red-bean.com/

Posted on January 21, 2010 at 10:05 am by Sami · Permalink
In: IT, Open Source · Tagged with: , , ,

Leave a Reply