How to play on SVN with (import, add, delete, checkout, commit & log) commands in linux

We have already discussed about SVN installation and configuration in our previous article, Here i’m going to play on my SVN Server by creating new project, import the project to SVN repo, adding & deleting files into SVN, viewing SVN history and finally show you how to rollback to older version.

Before entering into SVN door, we should aware few commands and basic things about it to play nicely.

# SVN mandatory commands #

# SVN import #
root@2daygeek [~]# svn import [Path] [URL or Path] -m [log message]

# SVN Checkout #
root@2daygeek [~]# svn co URL

# SVN Commit #
root@2daygeek [~]# svn commit -m "information"

# SVN Add #
root@2daygeek [~]# svn add [PATH]

# SVN Delete #
root@2daygeek [~]# svn remove [PATH]

# SVN Log #
root@2daygeek [~]# svn log [URL]

1) Creating new project

I’m going to create new project to play around SVN with files and directory. So that we can see the difference after making the changes.

# Navigate to /opt directory #
root@2daygeek [~]# cd /opt

# Create new directory for project #
root@2daygeek [~]# mkdir 2g-project

# Navigate to project directory #
root@2daygeek [~]# cd 2g-project

# Create some new directory into the project #
root@2daygeek [~]# mkdir 2g-dev 2g-main 2g-test

# Add some files into all the directories and write something inside the file #
root@2daygeek [~]# nano 2g-dev/index.php
root@2daygeek [~]# nano 2g-main/httpd.conf
root@2daygeek [~]# nano 2g-test/index.html

2) Importing the project into SVN

I’m going to import new project to local SVN server to move forward.

# Importing project to Local SVN Server #
root@2daygeek [~]# svn import /opt/2g-project/ file:///var/www/svn/repos/2g-project -m "Initial 

repository layout for 2g-project"
Adding         /opt/2g-project/2g-dev
Adding         /opt/2g-project/2g-dev/index.php
Adding         /opt/2g-project/2g-test
Adding         /opt/2g-project/2g-test/index.html
Adding         /opt/2g-project/2g-main
Adding         /opt/2g-project/2g-main/httpd.conf

Committed revision 1.

See the below output, it will clearly shows Revision 1. after importing the project.
svn-import-add-delete-checkout-commit-command-examples-1

3) Checking out the project remotely

We can check the same from other Linux machine remotely by checking out SVN command.

# Checking out the project remotely #
daygeek@2daygeek :~$ svn co http://192.168.1.100/repos/2g-project
Authentication realm:  Subversion repos
Password for 'mageshm':
A    2g-project/2g-dev
A    2g-project/2g-dev/index.php
A    2g-project/2g-test
A    2g-project/2g-test/index.html
A    2g-project/2g-main
A    2g-project/2g-main/httpd.conf
Checked out revision 1.

4) Edit & Commit

Here i’m going to edit the project file from my laptop to verify the changes.

# Editing the file contents #
daygeek@2daygeek :~$ nano 2g-dev/index.php

# Use commit command to save the modification in svn repo #
daygeek@2daygeek :~$ svn commit -m "Added a line into index.php file on 2g-dev folder."
Authentication realm:  Subversion repos
Password for 'mageshm':
Sending        2g-dev/index.php
Transmitting file data .
Committed revision 2.

Now, the above output shows revision 2. so my changes has been saved properly into svn repo. See the web output.
svn-import-add-delete-checkout-commit-command-examples-2

5) Adding new file into svn

Here i’m going to add new file into my svn repo.

# Copy the file into project #
daygeek@2daygeek :~$ cp /etc/httpd/conf/modsec2.conf 2g-dev/

# Add the file into svn repo #
daygeek@2daygeek :~$ svn add 2g-dev/modsec2.conf
A         2g-dev/modsec2.conf

# Use commit command to save the modification in svn repo #
daygeek@2daygeek :~$ svn commit -m "Added the Mode_Security conf file into 2g-dev folder."
Authentication realm:  Subversion repos
Password for 'mageshm':
Adding         2g-dev/modsec2.conf
Transmitting file data .
Committed revision 3.

Now, the above output shows revision 3. so my changes has been saved properly into svn repo. See the web output.
svn-import-add-delete-checkout-commit-command-examples-3

6) Deleting file from svn

Here i’m going to delete a file from my svn repo.

# Delete a file from svn repo #
daygeek@2daygeek :~$ svn delete 2g-main/httpd.conf
D         2g-main/httpd.conf

# Use commit command to save the modification in svn repo #
daygeek@2daygeek :~$ svn commit -m "Removed httpd.conf file from 2g-main folder."
Authentication realm:  Subversion repos
Password for 'mageshm':
Deleting       2g-main/httpd.conf
Committed revision 4.

Now, the above output shows revision 4. so my changes has been saved properly into svn repo. See the web output.
svn-import-add-delete-checkout-commit-command-examples-4

7) Checking svn revisions log

We can check the revisions log by using the below command.

# Delete a file from svn repo #
daygeek@2daygeek :~$ svn log http://192.168.1.100/repos
Authentication realm:  Subversion repos
Password for 'mageshm':

-----------------------------------------------------------------------
Store password unencrypted (yes/no)? no
------------------------------------------------------------------------
r4 | mageshm | 2015-10-14 18:21:29 +0530 (Wed, 14 Oct 2015) | 1 line

Removed httpd.conf file from 2g-main folder.
------------------------------------------------------------------------
r3 | mageshm | 2015-10-14 18:16:08 +0530 (Wed, 14 Oct 2015) | 1 line

Added the Mode_Security conf file into 2g-dev folder.
------------------------------------------------------------------------
r2 | mageshm | 2015-10-14 18:05:30 +0530 (Wed, 14 Oct 2015) | 1 line

Added a line into index.php file on 2g-dev folder.
------------------------------------------------------------------------
r1 | root | 2015-10-14 17:30:32 +0530 (Wed, 14 Oct 2015) | 1 line

Initial repository layout for 2g-project
------------------------------------------------------------------------

8) How to rollback previous version

Here i’m going to show you, how to
rollback your project to previous version.

# Rollback to previous version #
daygeek@2daygeek :~$ svn co -r 3 http://192.168.1.100/repos/2g-project
Authentication realm:  Subversion repos
Password for 'mageshm':

A    2g-project/2g-dev
A    2g-project/2g-dev/modsec2.conf
A    2g-project/2g-dev/index.php
A    2g-project/2g-test
A    2g-project/2g-test/index.html
A    2g-project/2g-main
A    2g-project/2g-main/httpd.conf
Checked out revision 3.

The above output clearly shows, i have rolled back from revision 4. to revision 3.

That’s it now, will comes with upgrade/install latest version of svn 1.9.2 article. Please stay tune us with 2daygeek for latest LINUX GEEKS…)

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

Leave a Reply

Your email address will not be published. Required fields are marked *