SVN Intro – Branching & Merging


We will create the SVN REPO using the

  • #svnadmin create sanoob.com   – @SVN Server

Now create 3 directory called Trunk, Branches, Tags

The working code is initially placed in the TRUNK dir

  • #vim wow.com/conf/passwd
  • abc 123
  • #svnserve -d

[Note: now a user abc with password 123 is created.]

@Dev

  • #telnet 22.22.22.22 3690
  • #svn co svn://22.22.22.22:/root/wow.com wow.com #cd wow.com #mkdir trunk branches tags
  • #svn add * #svn commit -m “Added  branch tags trunk”
  • #svn import ../repo/common/dbbackup svn://22.22.22.22:/root/wow.com/trunk -m “Adding Code to Trunk”
  • #svn cp svn://22.22.22.22:/root/wow.com/trunk svn://22.22.22.22:/root/wow.com/branches/sanoob -m “Giving Code to Developer sanoob”
  • #svn cp svn://22.22.22.22:/root/wow.com/trunk svn://22.22.22.22:/root/wow.com/branches/ammukutty -m “Giving Code to Developer Ammukutty”
  • #svn cp svn://22.22.22.22:/root/wow.com/trunk svn://22.22.22.22:/root/wow.com/branches/production -m “Placing Code on Production”

@Sanoob’s Machine

  • #svn co svn://22.22.22.22:/root/wow.com/branches/sanoob
Creating a New File (Hi.txt), modifying and Commiting it.
  • #echo Hiiiiiiiiiiiiiii > Hi.txt
  • #svn add Hi.txt
  • #svn ci -m “Deleted all and added Hi”

[NOTE: After editing a file an “SVN CI” has to be made to reflect the same on the Central Repo]

  • #svn status         – to know the added,modified or deleted status – Mostly applied to Dev Machines #echo rev2 unni > Hi.txt
  • #svn ci -m “changes to Hi.txt”

On a different machine where the checkout is already done then , the following command will update the status.

  • #svn up Hi.txt   – restore the status to a revision number latest in according to svn repo @ svn server

[NOTE: “SVN INFO” will show an updated Revision Number only if “SVN UP” is done]

To revert to a revision

  • #svp up -r 7             – Mass Updating

OR

  • #svp up [filename] -r 7  – Only one file is Updated

@Ammukutty’s Machine

  • #svn co svn://22.22.22.22:/root/wow.com/branches/ammukutty

@Production Server – always use “SVN UP”…….and never “SVN CO”

To DELETE a file both locally & repo simultaneously –  @ PRODUCTION SERVER

  • #svn delete testdir
  • #svn ci -m “Deleted testdir “

SVN Merging – @Sanoob (NOT applicable to merge multiple developers code)

  • #svn switch svn://22.22.22.22:/root/wow.com/branches/production
  • #svn up
  • #svn merge svn://22.22.22.22:/root/wow.com/branches/production svn://23.20.42.85:/root/wow.com/branches/sanoob
  • #svn ci -m “Merged Production with sanoob”

SVN Merging – @Production

  • #svn merge -r<NO1.>:<NO2.> path/of/developers/trunk

where

NO1. – revision number of current project – PRODUCTIONS – “Last Changed Revision”
NO2. – revision number of developer project – “Last Change Revision”

More Info

SVN Directory Structure
/trunk – Development sandbox for standard scenarios
/branches – Long Isolated work; Major Structural Changes
/tags – Stable, Numbered Versions Ready for Release

SVN Status –
!  – a file is deleted locally when compared to SVN Repo
A – a file is added to SVN Repo
U – a file is updated
C – a file conflict

SVN Starter

@SVN CENTRAL REPOSITORY

To Install SVN
#apt-get install subversion

To Create the SVN Repo
#svnadmin create sanoob.com

Under /sanoob.com/conf you will find repository configuration files, interesting for us at the moment are only passwd and svnserve.conf.

Edit the SVN Configuration File
#cd sanoob.com/
#vim conf/svnserve.conf

Edit also the svnserve.conf to have following contents:
[general]
anon-access = none
auth-access = write
password-db = passwd

Add the SVN User to the SVN
#vim conf/passwd

For testing edit the passwd file to have following contents
Entry: unni = 123unni

Notice that the password will be written in clear-text in this file, so for security reasons you might want NOT to use the same credentials as you use in your system as a login account (although if you make sure with chmod 600 passwd that only the user svnowner can access the file, the risk of someone being able to sneak a peak without administrative account or knowing the svnowner password is minimal).

Start SVN Server
#svnserve -d

[NOTE: SVN Port – 3690]

@DEV/LIVE INSTANCES

Make sure you have svn client tools installed on your computer. In command line issue:

If its for an already existing project say sanoob.com then to enable SVN for this Project,

Upload all the source code to the SVN Repo Initially

#svn import svn_monitored_dir svn://IPofSVN_CentralRepo:Location_of_SVN_repo@SVN_Svr
e.g:
#svn import public_html svn://24.24.24.24:/root/sanoob.com

AND, Bring down the first Check Out as Revision 1

#svn co svn://IPofSVN_Central_Repo:Location_of_SVN_Repo_ at_SVN_svr local_dir
e.g:
#svn co svn://24.24.24.24:/root/sanoob.com publicunni

ADD a New file and COMMIT IT
#cd [to the SVN Monitored Dir]
#echo “I am a Test” > test.txt
#svn add test.txt        [To add a bunch of files – #svn add *]
#svn ci -m “Commit test”

To get current SVN Revision Number
#svn info

To Update to Latest Changes
#svn up

To List the Modified Files
#svn status