Subversion (SVN) is Centralized, open-source Version Control System. SVN manages files and directories and changes made to them over a period of time, while supporting to shared development with features like rollback code conflict resolve. As well this allows to recover older versions of the software (data) or examine the history of how the code-base changed. SVN is developed in order to overcome the bugs and misfeatures of CVS.
In SVN there are two ends to deal with. One is the Subversion Repository which contains all the managed files and directories, and the other one is commandline or GUI client application to manage files from the client's end. It is important to know the concept of SVN repository before starting work with SVN.
Repository is a file server which is not behave like an usual one. It has it's own revisioning system. After any authorized person change a file in repository, the state of the code-base will change and it is given a index to identify that state which is new code-base. This index is called revision number. At the initial state of the repository revision number is '0'. For any change in repository the revision number will increase by one (Figure 1). So that people can refer the older versions of the code-base.
Figure 1 |
Usually repository contain three main directories containing the code-base.
- trunk - code-base of main development process
- branch - copy of specific revision, to implement new features(which takes some time to finish) concurrently and independently on top of that (Figure 2)
- tag - some snapshots of the trunk. Can store stable versions of the code-base
Figure 2 |
Even in branching process, the revision numbers are depend on changes of the branches (Figure 3). How ever at the end of the branching process of a particular branch, containing code should be merge with the main code-base (in trunk).
Figure 3 |
Now I think you have an idea on how the repository behave. To access SVN repository there are several methods. Following table shows the URL schemes map to each access method.
Scheme | Access Method |
---|---|
file:/// | Direct repository access (on local disk) |
http:// | Access via WebDAV protocol to Subversionaware Apache server |
https:// | Same as http://, but with SSL encryption |
svn:// | Access via custom protocol to an svnserve server |
svn+ssh:// | Same as svn://, but through an SSH tunnel |
As I mentioned earlier, the second end of SVN is the application, in client's end. I'll explain how we can generally use SVN client applications with Linux & windows environment.
Setup a repository
We can get use of sourceforge in order to setup a repository. sourceforge is free repository provider for open-source projects. What you have to do is register for the sourceforge and create a project. Make sure to select the version control system as SVN (default is git) while you are creating the project. sourceforge itself can add folders and files. But since we are in another track forget it for a moment. Under the code tab of your project home page, you can see the command you should use to get a checkout for linux based system. (make sure you have login)
With UBUNTU-10.04 OS
SVN commandline client can be used with Linux based systems. After installing the SVN commandline client, files can managed via executing the commands in command prompt.
install SVNcommandline client on your machine
$ sudo apt-get install subversion libapache2-svn
first go inside that directory and add source files to the repository.
$ cd /home/source_folder
$ svn import --username=your_username -m "Meaningfull_message_about_the_source_changes_for_users" url_of_repository
note : the repository url you can obtain from the sourceforge (sourceforge -> your project -> code tab)
In sourceforge project your initial file upload will appear as revision number 2. This is due to sourceforge itself create the general folder structure of repository and it will appear as revision number 1.
To start developing with SVN, first create a new folder and then get a checkout from the repository (copy of the latest code-base in repository)
To start developing with SVN, first create a new folder and then get a checkout from the repository (copy of the latest code-base in repository)
$ sudo mkdir /var/www/myproject
$ cd /var/www
$ svn co --username your_username url_of_repository myproject
$ svn add new_file_1 new_file_2
$ svn ci -m "Meaningful_Message" new_file_1 existing_file_1 existing_file_2
If you want to commit all the files you changed, you use above code without the file paths. A summery of some useful SVN commands are shown below.
information on usage of SVN
$ svn --help
initial commit
$ svn import --username=your_username -m "Message" URL
get a checkout
$ svn co --username your_username URL project_folder
make prepare to commit the newly added files (unversioned files)
$ svn add file_path
see the states of the files (whether versioned or unversioned)
$ svn st
note: The meaning of the symbols shown for statuses,
? - unversioned file
M - locally modified file
A - schedule to add the file
? - unversioned file
M - locally modified file
A - schedule to add the file
D - schedule to delete the file
G - merged file
C - conflicted file while updating (file is waiting for user resolve the conflict)
! - file is missing or incomplete (removed by non-svn command)
~ - versioned file obstructed by some file of a different kind
~ - versioned file obstructed by some file of a different kind
I - file ignored
get latest code to working copy without changing local modifications
$ svn up
note: If any file is about to conflict (overwrite) commandline client itself give some options to user to agree,
p - mark the conflict to be resolved later (postpone)
df - show all changes made to merged file (diff-full)
e - change merged file in an editor (edit)
r - accept merged version of file (resolved)
mf - accept my version of entire file and ignore their changes (mine-full)
tf - accept their version of entire file and lose my changes (theirs-full)
l - launch external tool to resolve conflict (launch)
h - show this list (help)
p - mark the conflict to be resolved later (postpone)
df - show all changes made to merged file (diff-full)
e - change merged file in an editor (edit)
r - accept merged version of file (resolved)
mf - accept my version of entire file and ignore their changes (mine-full)
tf - accept their version of entire file and lose my changes (theirs-full)
l - launch external tool to resolve conflict (launch)
h - show this list (help)
resolve conflicted file before commit (after postpone conflict we can manually resolve it)
$ svn resolved conflicted_file_path
commit all local changes
$ svn ci -m "Message"
note: to commit specific files, add file paths at the end of the above command separating each by a space
remove all the local changes of a working copy (become to base revision)
$ svn revert -R .
note: to revert specific file replace '-R .' with file path
information on base revision (revision of working copy on top)
$ svn info
modifications between working copy and base revision
$ svn diff
get file differences to a file
$ svn diff > ~/Desktop/path/filename.diff
apply patch (diff file) to working copy
SVN GUI client can be used for windows based systems. TortoiseSVN is the GUI client of SVN. After Installing Tortoise SVN on a machine, files can be managed in UI level. To start the development, go to any directory, under which this project should be created, then right click and select 'SVN checkout' option. Then you can give the repository URL and the local project directory name. If you have already created a project in sourceforge, from the SVN command appeared under 'code' tab, you can fetch out the repository URL.
After any improvement in the code, the corresponding file and all it's parent directories are shown as modified by a red mark on the file or directory. Using the right click options, the modified code can be committed (SVN commit) even while neglecting some of the modified files by selecting them. As well you can see lot of SVN operations can be done from this interface (Figure 4).
So if you are new to SVN, hope this will helpful to you.
$ svn patch -p0 ~/Desktop/path/filename.diff
With Widows 7 OS
SVN GUI client can be used for windows based systems. TortoiseSVN is the GUI client of SVN. After Installing Tortoise SVN on a machine, files can be managed in UI level. To start the development, go to any directory, under which this project should be created, then right click and select 'SVN checkout' option. Then you can give the repository URL and the local project directory name. If you have already created a project in sourceforge, from the SVN command appeared under 'code' tab, you can fetch out the repository URL.
After any improvement in the code, the corresponding file and all it's parent directories are shown as modified by a red mark on the file or directory. Using the right click options, the modified code can be committed (SVN commit) even while neglecting some of the modified files by selecting them. As well you can see lot of SVN operations can be done from this interface (Figure 4).
Figure 4 |