Linux SVN/Subversion Usefull commands


(A) How to install and Import directory into repository:
Click here

(B)How to get working copy from svn repository into local machine?
Goto Your home directory , example : cd /root
Now execute bellow commands

[root@mail ~]# svn checkout file:///svn
A    svn/script
A    svn/script/
A    svn/config
A    svn/config/httpd-vhosts
Checked out revision 2.

Now you will see there is a directory call svn has been created in to your home directory and this svn has all the files we added before
Example :

[root@mail ~]# ls
epel-release-5-3.noarch.rpm  script
[root@mail ~]# cd svn
[root@mail svn]# ls
config  script
[root@mail svn]# cd script/
[root@mail script]# ls
[root@mail script]# pwd
[root@mail script]#

NOte : If you want to just check out only one directory example script. then command would be :

[root@mail ~]# svn checkout file:///svn/script
A    script/
Checked out revision 2.

(C) How to get the Updated copy of the working directory

[root@mail script]# svn update
Updated to revision 3.
[root@mail script]#

While you are working on a file.if any one changes to that file and you want to download those changes, then svn update will give the up to date file.

(D) How to add directory or file to the repository

[root@mail script]# svn add
[root@mail script]#
Note : Dont forget to run bellow command to make the update permanently
svn commit

(E) How to delete file or directory

 [root@mail script]# svn delete 

(F) How to view overall changes of local modifications

[root@mail script]# svn status
A       check_ping
[root@mail script]#

(G) How to view the details of local modifications

For Every modifications( every files)
[root@mail script]# svn diff
Index: check_ping
--- check_ping  (revision 0)
+++ check_ping  (revision 0)
@@ -0,0 +1 @@
+This is a test insert
---        (revision 4)
+++        (working copy)
@@ -0,0 +1 @@
+This is a test line
[root@mail script]#
For a particular file:
[root@mail script]# svn diff
---        (revision 4)
+++        (working copy)
@@ -0,0 +1 @@
+This is a test line
[root@mail script]#

(H) How to commit changes ( update your working copy with svn repository)

   svn commit

Before committing , it will open vim editor and you need to insert some comments about what you updating for your/Other peoples references.

(I) How to check history ?
Ref :

[root@mail script]# svn log
r5 | root | 2010-02-25 14:10:45 +0000 (Thu, 25 Feb 2010) | 3 lines
Added Check_ping file
Modified check_cpu file
r4 | root | 2010-02-25 13:55:01 +0000 (Thu, 25 Feb 2010) | 2 lines
Added Check_cpu and Delete file
r3 | root | 2010-02-25 13:42:52 +0000 (Thu, 25 Feb 2010) | 2 lines
Just update
r1 | root | 2010-02-25 11:19:54 +0000 (Thu, 25 Feb 2010) | 2 lines
Just Adding a directory

Meaning of A,C,D,M:

A item
    The file, directory, or symbolic link item has been scheduled for addition into the repository.
C item
    The file item is in a state of conflict. That is, changes received from the server during an update overlap with local changes that you have in your working copy (and weren't resolved during the update). You must resolve this conflict before committing your changes to the repository.
D item
    The file, directory, or symbolic link item has been scheduled for deletion from the repository.
M item
    The contents of the file item have been modified.

How to install Subversion


(A) To install Subversion : yum install mod_dav_svn subversion
(B) How to create a Repo :

svnadmin create /svn

So it will create a svn directory under / directory

[root@mail /]# pwd
[root@mail /]# ls  boot      dev   lib    opt   sbin     svn  usr
aquota.user   conffile  etc   media  proc  selinux  sys  var
bin           data      home  mnt    root  srv      tmp
[root@mail /]#

(C) How to import Directory in svn repos ?

 svn import directory/ file:///svn/directory

output :

[root@mail /]# svn import /root/script/ file:///svn/script
Adding         /root/script/
Committed revision 1.

Note After typing the svn import command it will open a Vim editor ,and will ask you to write some comments about this import
Example: I would of write: I am adding the /root/script directory into svn repository.

Svn Asking to input comments before adding directory to repository

Svn Asking to input comments before adding directory to repository

Note : if you see bellow error :

svn: Could not use external editor to fetch log message; consider setting the $SVN_EDITOR environment variable or using the --message (-m) or --file (-F) options
svn: None of the environment variables SVN_EDITOR, VISUAL or EDITOR are set, and no 'editor-cmd' run-time configuration option was found

which means: you need to add “vim ” program path into bash_profile files

How to add vim programm path in .bash_profile file :

vi /root/.bash_profile
add this line :
export SVN_EDITOR="/bin/vi"

Now save the file and logoff and log on agian

(d) How to check list of projects in svn repo

[root@mail /]# svn list file:///svn

Output :


Which means script directory has been added into svn repository.
Now if you want to see what is inside script directory

[root@mail /]# svn list file:///svn/script