Their are many version control software available in market. Subversion/svn can be said market leader atleast for centralized systems. Today I can discuss some most used svn client commands for better project handling.
First you need to install subversion, So fire apt-get command on your shell window.
$ apt-get install subversion
Now subversion is installed on your system.
First command you need is cloning the repository into your local system. So you need to take svn checkout for that repository.
$ svn checkout https://svn.yourdomain.com/project123/branches/dev
you can also use short word co instead of checkout.
After checkout we need some work. So let create a file test.php and put some code into it. Now if we analyze through following command we see output like this
$ svn status
? mark says that it is still not part of your svn repository. You need to add it by
$ svn add test.php
You can use bash expression like test.* or folder/*php or similar to add multiple files/folder into svn.
now if you use svn status, output is different then previous
$ svn status
This changes is local till now, And we need to commit the changes on server.
$ svn commit test.php -m 'ADD MESSAGE'
If you skip message part through line a default shell editor (like nano/vim) opened to fill message, You entered and save/exit through editor Then file is commited as previous command
$ svn commit test.php
You can also remove the any file in svn by using svn delete command. It works on local copy like svn add does and requires svn commit after it to done actually on server.
$ svn delete test.php
$ svn commit test.php -m 'DELETE MESSAGE'
Now Let if you added a file, remove a file or make changes in any of file, But not commited that file on server. You can revert your changes using revert command.
$ svn revert test.php
Afte verify on svn status you will found that,
This command removed the A flag and Add ? on previously svn added file
This command removed the D flag on previously svn deleted file
This command removed the U flag on previously updated file
NOTE : In any case commited changes can not be reverted through revert command.
For take latest changes from server, we need update command. This is little tricky as It will involve merge your changes with updates comes from server. And most challenging part of svn is to take care of it.
$ svn update
These are most common updates return from server.
- A denotes any newly added file on server added to your local structure.
- D denotes any any file is deleted on your local structure as that file is rmeoved on svn serve too .
- U denotes simple update on any file when you have not any local changes.
- G denotes simple update on any file when you have any local changes but not on same line.
- C denotes simple update on any file when you have any local changes on same line.
There are chances when update comes on file where you have any local changes on same line. Then their would be a prompt for conflict management with options p – postpone, df – diff, mc – mine-conflict, tc – their conflict. More
- df option show the diff of both version.
- mc option merge updations with the case that in case of same line conflict, local changes will be taken.
- tc option merge updations with the case that in case of same line conflict, remote changes will be taken.
- p option merge both version with conflict lines/part will be shown as <<< >>> block. That need to resolved first to commit. It also create some more files like test.php.mine, test.php.r101, test.php.r104. Where test.php.mine is local file before potpone merging. test.php.r104 or test.php.r<remote version> file having remote changes. test.php.r101 or test.php.r<remote previous version> file having previous remote commited version changes.
After using postpone options and creating required changes, You need to resove conflict by
$ svn resolve test.php
There are two options available but not shown in prompt.
- mf option discard remote file changes and take local file as verify version.
- tf option discard local file changes file and take remote file as verify version.
NOTE 1 : You need to commit changes in case of svn update file status G and C.
NOTE 2 : You may need to enter svn username/password in case of svn checkout/update/commit
That all for this article, We will discuss some more interesting features of svn in next article.