SVN Best Practices
Upcoming SlideShare
Loading in...5
×
 

SVN Best Practices

on

  • 6,187 views

 

Statistics

Views

Total Views
6,187
Views on SlideShare
6,140
Embed Views
47

Actions

Likes
11
Downloads
234
Comments
0

2 Embeds 47

https://confluence.novatec-gmbh.de 36
http://www.slideshare.net 11

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

SVN Best Practices SVN Best Practices Presentation Transcript

  • Subversion: Best Practices Adam Backstrom April 30, 2009
  • What is svn?
  • What is svn? index.php index.php index.php r956 r1281 r1305
  • What is svn? index.php index.php index.php r956 r1281 r1305
  • What is svn?
  • What is svn?
  • What is svn? r1305
  • What is svn? r1305 HEAD, BASE, {2009-02-01}
  • What is svn?
  • What is svn?
  • What is svn?
  • What is svn?
  • What is svn?
  • What is svn? svn branch svn merge
  • svn checkout
  • svn checkout adam:igrad$ svn co svn://io/repos/trunk
  • svn checkout adam:igrad$ svn co svn://io/repos/trunk A trunk/common.php A trunk/index.html A trunk/images A trunk/images/header.png Checked out revision 55. adam:igrad$
  • svn checkout svn co svn://io/repos/trunk [dirname]
  • The Basics Glossing over these. Use them in preference to the normal shell commands (or your editor’s file browser functions). svn actions maintain log history, so use them.
  • The Basics Glossing over these. Use them in preference to the normal shell commands (or your editor’s file browser functions). svn actions maintain log history, so use them. svn add rm svn delete rmdir svn copy cp svn move mv
  • The Basics Glossing over these. Use them in preference to the normal shell commands (or your editor’s file browser functions). svn actions maintain log history, so use them. svn add rm svn delete rmdir svn copy cp svn move mv
  • The Basics Glossing over these. Use them in preference to the normal shell commands (or your editor’s file browser functions). svn actions maintain log history, so use them. svn add rm svn delete rmdir svn copy cp svn move mv
  • svn checkin svn ci svn ci common.php svn ci common.php includes/
  • svn checkin Flags are a good way to commit more than you intended. Leave them out and svn will prompt you for a message. check_deps https://io.plymouth.edu/ trac/search svn ci -F message.txt svn ci -m ‘making some changes’
  • svn checkin Flags are a good way to commit more than you intended. Leave them out and svn will prompt you for a message. check_deps https://io.plymouth.edu/ trac/search svn ci -F message.txt svn ci -m ‘making some changes’
  • svn checkin Flags are a good way to commit more than you intended. Leave them out and svn will prompt you for a message. check_deps https://io.plymouth.edu/ trac/search svn ci -F message.txt svn ci -m ‘making some changes’
  • You will probably need to svn checkin define your editor. This code does it automatically at login. tcsh$ echo setenv EDITOR vi >> ~/.cshrc bash$ echo export EDITOR=vi >> ~/.bashrc
  • svn checkin Checkin after distinct changes. Simplify rollbacks, keep out the cruft when we look at changesets. Project TODO: •Verbiage changes •Update to authZ/authN •Alphabetize functions.php
  • svn checkin Checkin after distinct changes. Simplify rollbacks, keep out the cruft when we look at changesets. Project TODO: •Verbiage changes svn ci •Update to authZ/authN •Alphabetize functions.php
  • svn checkin Checkin after distinct changes. Simplify rollbacks, keep out the cruft when we look at changesets. Project TODO: •Verbiage changes svn ci •Update to authZ/authN svn ci •Alphabetize functions.php
  • svn checkin Checkin after distinct changes. Simplify rollbacks, keep out the cruft when we look at changesets. Project TODO: •Verbiage changes svn ci •Update to authZ/authN svn ci •Alphabetize functions.php svn ci
  • This should become habit. svn update Prevent conflicts (changing lines of code that have already been changed in the repos). Can’t checkin an out-of- date working directory. Update working directory from the remote repository. •Before you start editing •Before you commit
  • svn update Update multiple directories/files in one pass. svn up /web/includes_psu/PSUDatabase.class.php > /web/includes_external/adodb5 > /web/pscpages/webapp/ape/common.php
  • Should also become habit. svn status You’re scheduling commits for a reason, don’t let older changes creep into your commit. Lots of codes to choose from. Summarize changes in working directory. •Before you start editing •Before you commit M images/title.png A includes ? includes/functions.php D common.php
  • Should also become habit. svn status You’re scheduling commits for a reason, don’t let older changes creep into your commit. Lots of codes to choose from. Summarize changes in working directory. •Before you start editing •Before you commit M images/title.png A includes ? includes/functions.php D common.php
  • Should also become habit. svn status You’re scheduling commits for a reason, don’t let older changes creep into your commit. Lots of codes to choose from. Summarize changes in working directory. •Before you start editing •Before you commit M images/title.png A includes ? includes/functions.php D common.php
  • Should also become habit. svn status You’re scheduling commits for a reason, don’t let older changes creep into your commit. Lots of codes to choose from. Summarize changes in working directory. •Before you start editing •Before you commit M images/title.png A includes ? includes/functions.php D common.php
  • Should also become habit. svn status You’re scheduling commits for a reason, don’t let older changes creep into your commit. Lots of codes to choose from. Summarize changes in working directory. •Before you start editing •Before you commit M images/title.png A includes ? includes/functions.php D common.php
  • svn help svn help status svn help commit svn help checkout svn help di svn help blame Version Control with Subversion http://svnbook.red-bean.com/
  • Structure svn://io/repos/trunk Production Code Development svn://io/repos/branches Branches svn://io/repos/tags Named Snapshots
  • The current state of our Trunk web world. Should be able to checkout trunk at any time to bring up a new server. Our “Real” applications New web server = new trunk checkout
  • Break out a code base Branches into its own world. Allows you to commit changes to an application without affecting the trunk. svn://io/repos/branches/ape-authz svn:// io/repos/branches/igrad-1-0 svn://io/repos/branches/surplus-porter
  • Directories locked in Tags time. Snapshots. “Locked” only by convention. Tags give revision numbers a name. svn://io/repos/tags/ape-1-0 svn://io/repos/tags/adodb-5-0-8 ape-1-0 ape-1-1 ape-2-0
  • Directories locked in Structure time. Snapshots. “Locked” only by convention. Tags give revision numbers a name. branches/ trunk/ tags/
  • PSU Structure repos/ webapp/ trunk/ ape/ igrad branches/ ape-authz/ tags/ banner/ trunk/ branches/ tags/
  • svn diff
  • svn diff r1
  • svn diff r1 r2
  • svn diff r1 r2 r3
  • svn diff r1 r2 r3 + + -r1:2
  • svn diff r1 r2 r3 + - + + -r1:2 -r2:3
  • svn diff r1 r2 r3 svn di -r1:3 - + + +
  • svn diff r1 r2 r3 svn di -r1:3 - + + +
  • svn diff r1 r2 r3 svn di -r1:3 - + + +
  • svn diff r1 r2 r3 svn di -r1:3 - + + +
  • svn diff r1 r2 r3 svn di -r1:3 - + + +
  • svn diff r1 r2 r3 svn di -r3:1 + - - -
  • svn diff adam@flit:project$ svn di Index: common.php ==================================================== =============== --- common.php (revision 1) +++ common.php (working copy) @@ -7,7 +7,7 @@ require_once('PSUDatabase.class.php'); -$GLOBALS['BANNER'] = PSUDatabase::connect('oracle/psc1_psu'); +$GLOBALS['BANNER'] = PSUDatabase::connect('oracle/test_psu'); $admin = $GLOBALS['BANNER']->GetOne(quot;SELECT 1 FROM users WHERE pidm = …
  • svn diff adam@flit:project$ svn di Index: common.php ==================================================== =============== --- common.php (revision 1) +++ common.php (working copy) @@ -7,7 +7,7 @@ require_once('PSUDatabase.class.php'); -$GLOBALS['BANNER'] = PSUDatabase::connect('oracle/psc1_psu'); +$GLOBALS['BANNER'] = PSUDatabase::connect('oracle/test_psu'); $admin = $GLOBALS['BANNER']->GetOne(quot;SELECT 1 FROM users WHERE pidm = …
  • Use diff to pull out svn diff uncommitted changes into a single file. Email file around, save for later, etc. Alternative to branching. adam@flit:project$ svn di > changes.di # archive adam@flit:project$ svn revert -R . # back out changes [edit files, merge, cp, etc.] adam@flit:project$ svn ci # checkin new changes adam@flit:project$ patch -p0 < changes.di # apply archive
  • Show changes bet ween svn diff last checked out version (NOT including changes we made) and the most recent version. adam@flit:project$ svn di -r BASE:HEAD
  • Branching
  • svn copy Copies are cheap. Same files on the backend, just a new name for them. Create tags and branches the same way. adam@flit:project$ svn cp svn://io/repos/trunk > svn://io/repos/branches/banner8 Committed revision 12. adam@flit:project$
  • svn sw Easy to switch bet ween trees. Also easy to shoot yourself in the foot. (Coming up next slide.) adam@flit:project$ svn sw > svn://io/repos/branches/banner8 At revision 3. adam@flit:project$
  • svn sw See that switching bet ween branches will update all files within that branch. Unpredictable if you switch bet ween t wo unrelated directories. Works fine bet ween t wo “clean” checkouts with no modifications. adam@flit:project$ svn sw > svn://io/repos/branches/banner8 U index.html D includes/functions.inc.php A includes/functions.php Updated to revision 4. adam@flit:project$
  • svn sw Switching with changes in the tree. Will merge if possible. Works fine if you are working on trunk, then create a branch and switch to it. (Changes from trunk will be applied to branch cleanly.) You’ll get conflicts if you switch back to trunk. adam@flit:project$ svn sw > svn://io/repos/branches/banner8 G index.html Updated to revision 5. adam@flit:project$
  • svn info Find out where you are. adam@flit:project$ svn sw > svn://io/repos/branches/banner8 adam@flit:project$ svn info Path: . URL: svn://io/repos/branches/banner8 Repository Root: svn://io/repos/ Repository UUID: bb1ebae7-95e1-0310-b179-bb68cf00a8bd Revision: 55 Node Kind: directory Schedule: normal Last Changed Author: adam Last Changed Rev: 55 Last Changed Date: 2009-03-30 21:21:56 -0400 (Mon, 30 …
  • svn merge
  • svn merge adam@flit:project$ svn sw [branch path]
  • svn merge adam@flit:project$ svn sw [branch path] adam@flit:project$ vi index.html common.php
  • svn merge adam@flit:project$ svn sw [branch path] adam@flit:project$ vi index.html common.php adam@flit:project$ svn rm images/header.big.png
  • svn merge adam@flit:project$ svn sw [branch path] adam@flit:project$ vi index.html common.php adam@flit:project$ svn rm images/header.big.png adam@flit:project$ svn ci Sending index.html Sending common.php Deleting images/header.big.png Committed revision 9.
  • svn merge adam@flit:project$ svn sw [branch path] adam@flit:project$ vi index.html common.php adam@flit:project$ svn rm images/header.big.png adam@flit:project$ svn ci Sending index.html Sending common.php Deleting images/header.big.png Committed revision 9. adam@flit:project$ svn merge -r5:9 svn://io/repos/trunk . U index.html A images/background.png adam@flit:project$ svn ci
  • svn merge adam@flit:project$ svn sw [branch path] adam@flit:project$ vi index.html common.php adam@flit:project$ svn rm images/header.big.png adam@flit:project$ svn ci Sending index.html Sending common.php Deleting images/header.big.png Committed revision 9. adam@flit:project$ svn merge -r5:9 svn://io/repos/trunk . U index.html A images/background.png Range of revisions since adam@flit:project$ svn ci branch broke from trunk
  • svn merge Imagine a timeline like this: branch created in rev 4, changes made to trunk and branch, currently at rev 12. How to merge in new changes from trunk 6 and 9-12? trunk/ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 branches/rel-1-1/
  • svn merge Imagine a timeline like this: branch created in rev 4, changes made to trunk and branch, currently at rev 12. How to merge in new changes from trunk 6 and 9-12? trunk/ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 branches/rel-1-1/
  • svn merge Imagine a timeline like this: branch created in rev 4, changes made to trunk and branch, currently at rev 12. How to merge in new changes from trunk 6 and 9-12? trunk/ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 branches/rel-1-1/ svn merge -r4:HEAD svn://io/repos/trunk .
  • Conflicts Image ©2006 Eric Joyner
  • Conflicts $db = PSUDatabase::connect('oracle/psc1_psu');
  • Conflicts $db = PSUDatabase::connect('oracle/psc1_psu'); Trunk $db = PSUDatabase::connect('oracle/psc1_psu/fixcase');
  • Conflicts $db = PSUDatabase::connect('oracle/psc1_psu'); Trunk $db = PSUDatabase::connect('oracle/psc1_psu/fixcase'); Branch $db = new PSUDatabase('oracle/psc1_psu');
  • Conflicts adam@flit:project$ svn merge -r4:16 > svn://io/repos/trunk C common.php adam@flit:project$ svn st ? common.php.merge-left.r11 ? common.php.merge-right.r12 ? common.php.working C common.php
  • Conflicts <<<<<<< .working $GLOBALS['BANNER'] = new PSUDatabase('oracle/psc1_psu'); ======= $GLOBALS['BANNER'] = PSUDatabase::connect('oracle/psc1_psu/fixcase'); >>>>>>> .merge-right.r12
  • Conflicts adam@flit:project$ svn merge -r4:16 > svn://io/repos/trunk C common.php adam@flit:project$ svn st ? common.php.merge-left.r11 ? common.php.merge-right.r12 ? common.php.working C common.php adam@flit:project$ svn resolved common.php Resolved conflicted state of 'common.php'
  • Thanks.