Working with subversion – II

In previous article, I discuss some basic functions of svn. Now i will discuss some more handful features for svn.

But first one disclaimer I will only show some basic example for svn commands. They are very powerful and can be used with variety of parameter to achieve required results.

First sometimes we need to know about our svn setup. So svn info comes as handy here.

$ svn info
URL: https://svn.yourdomain.com/project123/branches/dev
Repository Root: https://svn.yourdomain.com
Repository UUID: 3aaa9e22-3660-1222-1111-ccca444822
Revision: 10
Node Kind: directory
Schedule: normal
Last Changed Author: User1
Last Changed Rev: 10
Last Changed Date: 2013-03-13 01:23:12 +0530 (Wed, 13 Mar 2013)

As you see it gives information like SVN url total revision last commited revision info etc.
Some times we will need to analyze the changes log. For that svn log command is very handful.
Syntax : svn log <File Path>

$ svn log test.php
------------------------------------------------------------------------
r2 | user2 | 2013-03-13 01:23:12 +0530 (Wed, 13 Mar 2013) | 2 lines
some changes
------------------------------------------------------------------------
r1 | user1 | 2013-03-13 01:14:14 +0530 (Wed, 13 Mar 2013) | 1 line
First code commit

This is helpful to check which user commited which version. You can also track down the previous version file contents through svn cat command
Ex. for check test.php for version 123

Syntax : svn cat -r<revision> <File Path>

Example

$ svn cat -r123 test.php

For save into file to analyze, use bash stdout like that

$ svn cat -r123 test.php > test-prev.php

One more command is very much used for track down changes between versions and that is svn  diff

Syntax : svn diff <File Path>

Example

$ svn diff test.php

Above command returns the difference between latest commited version and uncommited changes for test.php. You also can check difference from any particular revision by pass revision.

Syntax : svn diff -r<revision> <File Path>

Example for Changes in test.php after version 4.

$ svn diff -r4 test.php

Their are times when you need structure without svn footprints (folders/files related to svn ) Example to upload somewhere. You need svn export command.

Syntax : svn export <Folder Path to export structure >

Example

$ svn export /home/user/backups/

It will create project123 folder into /home/user/backups/. Remember it will create folder, you should not create folder at that path with same name.

I hope these cheat sheet for svn is usable for readers

Working with subversion – I

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.

Ex.
$ 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
? test.php

? 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
A test.php

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
A test.php
D test1.php
U test2.php
G test3.php
C test4.php

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.