As I discussed earlier that we conduct very interesting event in our Apptility that is 3:30@Lab. So this time one of software engineer discussed this topic:

21 SVN commands every serious developer should know.

I am trying to post some parts of that session over here. Hope that it will be useful for that guys who are working on Open Source.

1. Help:
Before reading on, here is the most important command you’ll ever need when using Subversion: svn help. The Subversion command-line client is self-documenting—at any time,.

$svn help
Will display all available subcommands in svn. A quick svn help SUBCOMMAND will describe the syntax, switches, and behavior of the subcommand:

$svn help checkout

2. checkout: Check out a working copy from a repository.

$svn checkout URL… [PATH]

ex: This copy contains the HEAD (latest revision) of the Subversion repository that you specify on the command line.
$ svn checkout

Although the above example checks out the trunk directory, you can just as easily check out any deep subdirectory of a repository by specifying the subdirectory in the checkout URL:

$svn checkout
To checkout a specific revision:
$svn checkout -r 8810

If you have username and password in repository then
$svn checkout –username <USER> –password <PASSWORD>

3. update: Your Working Copy
$ svn update
If no revision given, bring working copy up-to-date with HEAD rev.
Else synchronize working copy to revision given by -r.

For each updated item a line will start with a character reporting the
action taken. These characters have the following meaning:

A Added
D Deleted
U Updated
C Conflict
G Merged

4. status: See an overview of your changes:
$ svn status
If you run svn status at the top of your working copy with no arguments, it will detect all file and tree changes you’ve made.
Most common status codes that svn status can return:
‘ ‘ ## no modifications
A mydir/foo.h ## file is scheduled for addition, this is new file, not in the repos
C mydir/test/bar.c ## file has conflicts from an update
D mydir/fish.c ## file is scheduled for deletion
M bar.c ## the content in bar.c has local modifications
? foo.h ## item is not under version control
! bar.h ## item is missing (removed by non-svn command) or incomplete

5. diff: To see details of your local modifications:
$ svn diff

Output is displayed in unified diff format. That is, removed lines are prefaced with a – and added lines are prefaced with a +

6. revert: Undoing Working Changes
$ svn revert bar.c
Subversion reverts the file to its pre-modified state by overwriting it with the cached copy from the .svn folder.
By mistake you removed a file from version control:

$ svn status bar.c

$ svn delete bar.c
D bar.c ## D: status code for delete

$ svn revert bar.c
Reverted ‘bar.c’

$ svn status bar.c

7. resolved: Resolving Conflicts: Conflicts come when there is some changes at the same line in the working copy and copy from repository.

We can predict conflict in files without updating it, just by using status command with -u switch
$svn status -u

$ svn update
C bar.h

This means that the changes from the repository overlapped with your own.
Status code ‘C’ during the update means that the file is in a state of conflict.
For every conflicted file, Subversion places three extra unversioned files in your working copy
bar.h.mine ##This is your file as it existed in your working copy before you updated your working ##copy; ie, without conflict markers
bar.h.rOld ##This is the file that was the BASE revision before you updated your working copy. bar.h.rNew ##Latest revision in the repository.

Example of conflicted file:
$ cat bar.h
<<<<<<< .mine
>>>>>>> .rN
South Africa
The strings of ‘<<<‘, ‘===’, and ‘>>>’ signs are conflict markers.
You want to ensure that those are removed from the file before your next commit.
The text between the first two sets of markers is composed of the changes you made in the conflicting area:
<<<<<<< .mine

The text between the second and third sets of markers is the text from others commit:

>>>>>>> .rN

Now you have to resolve the conflicts by:
Merge the conflicted text by hand. Or remove your local changes by running:

$ svn revert bar.h // to throw away all of your local changes.

Once you’ve resolved the conflict, you need to let Subversion know by running svn resolved. This removes the three temporary files and Subversion no longer considers the file to be in a state of conflict.
$ svn resolved bar.h

8. commit: Send changes from your working copy to the repository.
$svn commit [PATH…]

A log message must be provided, but it can be empty. If it is not
given by a –message or –file option, an editor will be started.
$ svn commit -m “included header file.” bar.h

9. list: List directory entries in the repository.
$ svn list Target
List each TARGET file and the contents of each TARGET directory as
they exist in the repository. If TARGET is a working copy path, the
corresponding repository URL will be used.

The default TARGET is ‘.’, meaning the repository URL of the current
working directory.

svn list is most useful if you want to see what files a repository has without downloading a working copy:

$ svn list

10. add: Add files, directories, or symbolic links to your working copy and schedule them for addition to the repository.
They will be uploaded and added to the repository on your next commit. If you add something and change your mind before committing, you can unschedule the addition using svn revert.

$svn add PATH

To add a file to working copy:
$ svn add foo.txt
A foo.txt ## A: status code Added

When adding a directory, the default behavior of svn add is to recurse:

$ svn add MyDir
A MyDir
A MyDir/a
A MyDir/b

11. lock: Lock working copy paths or URLs in the repository, so that no other user can commit changes to them.
svn lock TARGET…

Lock two files in your working copy:
$ svn lock config.php config.png
‘config.php’ locked by user ‘sanjay’.
‘config.png’ locked by user ‘sanjay’.

Lock a file in repository:

$ svn lock
‘config.php’ locked by user ‘sanjay’.

12. log: Display commit log messages.
svn log URL [PATH…]
The default target is the path of your current directory. If no arguments are supplied, svn log shows the log messages for all files and directories inside of (and including) the current working directory of your working copy.

You can see the log messages for all the paths that changed in your working copy by running svn log from the top:
$svn log

All log messages for a particular file in your working copy:
$ svn log foo.h

Log for a particular revision(20):
$svn log -r 20 foo.h
Log for range of revisions(from 20 to 25)
$svn log -r 20:25 foo.h

13. unlock: Unlock working copy paths or URLs.
svn unlock TARGET…

Unlock two files in your working copy:
$ svn unlock config.php config.png
‘config.php’ unlocked.
‘config.png’ unlocked’.

Unlock a file in repository:

$ svn unlock
‘config.php’ unlocked

14. delete: — Delete an item from a working copy or the repository.

svn delete PATH…
svn delete URL…

Using svn to delete a file from your working copy only schedules it to be deleted. When you commit, the file is deleted in the repository.

$ svn delete myfile
D myfile

$ svn commit -m “Deleted file ‘myfile’.”
Deleting myfile
Transmitting file data .
Committed revision 22.

Deleting a URL, however, is immediate, so you have to supply a log message:

$ svn delete -m “Deleting file ‘myfile'”

Committed revision 25.

15. import: Commit an unversioned file or tree into the repository
svn import [PATH] URL

Recursively commit a copy of PATH to URL. If PATH is omitted “.” is assumed. Parent directories are created in the repository as necessary.
This imports the local directory myproj into the root of your repository:

$ svn import -m “New import” myproj

16. export: Export a clean directory tree.

svn export [-r REV] URL [PATH]

svn export [-r REV] PATH1 [PATH2]

The first form exports a clean directory tree from the repository specified by URL, at revision REV if it is given, otherwise at HEAD, into PATH. If PATH is omitted, the last component of the URL is used for the local directory name.

The second form exports a clean directory tree from the working copy specified by PATH1 into PATH2. All local changes will be preserved, but files not under version control will not be copied.
Export directly from the repository:
$ svn export myApp

17. cat: Output the contents of the specified files or URLs.
svn cat TARGET

If you want to view config.txt in your repository without checking it out:

$ svn cat

18. mkdir: Create a new directory under version control.

svn mkdir PATH…
svn mkdir URL…

Create a directory with a name given by the final component of the PATH or URL. A directory specified by a working copy PATH is scheduled for addition in the working copy. A directory specified by a URL is created in the repository via an immediate commit.

Create a directory in your working copy:

$ svn mkdir newdir
A newdir

Create one in the repository (instant commit, so a log message is required):
$ svn mkdir -m “Making a new dir.”

19. move: Move a file or directory.

svn move SOURCE DEST

This command moves a file or directory in your working copy or in the repository.
This command is equivalent to an svn copy followed by svn delete.

Move a file in your working copy:
$ svn move foo.c bar.c
A bar.c ##added
D foo.c ##deleted

Move a file in the repository (an immediate commit, so it requires a commit message):

$ svn move -m “Move a file”

20. blame: Show author and revision information in-line for the specified files or URLs.

svn blame TARGET[@REV]…

Show author and revision information in-line for the specified files or URLs. Each line of text is annotated at the beginning with the author (username) and the revision number for the last change to that line
$ svn blame

21. copy: Copy a file or directory in a working copy or in the repository.
svn copy SOURCE DEST

Copy a file in a working copy or in the repository. SOURCE and DEST can each be either a working copy path or URL.

Copy an item within your working copy (just schedules the copy—nothing goes into the repository until you commit):

$ svn copy foo.txt bar.txt
A bar.txt

Copy an item in your working copy to a URL in the repository (an immediate commit, so you must supply a commit message):

$ svn copy my.txt -m “Remote copy.”

Copy an item from the repository to your working copy (just schedules the copy—nothing goes into the repository until you commit):
(This is the recommended way to resurrect a dead file in your repository)

$ svn copy
A my.txt ##A: added


8 thoughts on “SVN COMMANDS

  1. Ever heared of TortoiseSvn?
    Don’t get me wrong, I like the command line, but why using command line when you have such a powerful tool for Microsoft Windows?
    Similar Tools exist for unix etc.

  2. @Robert: Everyone who has used the command line and seen the woes of tools like Tortoise will never want that GUI shit again.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s