SVN Best Practices

5,295 views
5,166 views

Published on

Published in: Technology
0 Comments
12 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,295
On SlideShare
0
From Embeds
0
Number of Embeds
49
Actions
Shares
0
Downloads
269
Comments
0
Likes
12
Embeds 0
No embeds

No notes for slide





















































































  • SVN Best Practices

    1. 1. Subversion: Best Practices Adam Backstrom April 30, 2009
    2. 2. What is svn?
    3. 3. What is svn? index.php index.php index.php r956 r1281 r1305
    4. 4. What is svn? index.php index.php index.php r956 r1281 r1305
    5. 5. What is svn?
    6. 6. What is svn?
    7. 7. What is svn? r1305
    8. 8. What is svn? r1305 HEAD, BASE, {2009-02-01}
    9. 9. What is svn?
    10. 10. What is svn?
    11. 11. What is svn?
    12. 12. What is svn?
    13. 13. What is svn?
    14. 14. What is svn? svn branch svn merge
    15. 15. svn checkout
    16. 16. svn checkout adam:igrad$ svn co svn://io/repos/trunk
    17. 17. 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$
    18. 18. svn checkout svn co svn://io/repos/trunk [dirname]
    19. 19. 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.
    20. 20. 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
    21. 21. 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
    22. 22. 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
    23. 23. svn checkin svn ci svn ci common.php svn ci common.php includes/
    24. 24. 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’
    25. 25. 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’
    26. 26. 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’
    27. 27. 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
    28. 28. 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
    29. 29. 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
    30. 30. 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
    31. 31. 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
    32. 32. 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
    33. 33. 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
    34. 34. 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
    35. 35. 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
    36. 36. 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
    37. 37. 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
    38. 38. 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
    39. 39. 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/
    40. 40. Structure svn://io/repos/trunk Production Code Development svn://io/repos/branches Branches svn://io/repos/tags Named Snapshots
    41. 41. 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
    42. 42. 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
    43. 43. 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
    44. 44. Directories locked in Structure time. Snapshots. “Locked” only by convention. Tags give revision numbers a name. branches/ trunk/ tags/
    45. 45. PSU Structure repos/ webapp/ trunk/ ape/ igrad branches/ ape-authz/ tags/ banner/ trunk/ branches/ tags/
    46. 46. svn diff
    47. 47. svn diff r1
    48. 48. svn diff r1 r2
    49. 49. svn diff r1 r2 r3
    50. 50. svn diff r1 r2 r3 + + -r1:2
    51. 51. svn diff r1 r2 r3 + - + + -r1:2 -r2:3
    52. 52. svn diff r1 r2 r3 svn di -r1:3 - + + +
    53. 53. svn diff r1 r2 r3 svn di -r1:3 - + + +
    54. 54. svn diff r1 r2 r3 svn di -r1:3 - + + +
    55. 55. svn diff r1 r2 r3 svn di -r1:3 - + + +
    56. 56. svn diff r1 r2 r3 svn di -r1:3 - + + +
    57. 57. svn diff r1 r2 r3 svn di -r3:1 + - - -
    58. 58. 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 = …
    59. 59. 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 = …
    60. 60. 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
    61. 61. 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
    62. 62. Branching
    63. 63. 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$
    64. 64. 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$
    65. 65. 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$
    66. 66. 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$
    67. 67. 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 …
    68. 68. svn merge
    69. 69. svn merge adam@flit:project$ svn sw [branch path]
    70. 70. svn merge adam@flit:project$ svn sw [branch path] adam@flit:project$ vi index.html common.php
    71. 71. 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
    72. 72. 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.
    73. 73. 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
    74. 74. 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
    75. 75. 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/
    76. 76. 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/
    77. 77. 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 .
    78. 78. Conflicts Image ©2006 Eric Joyner
    79. 79. Conflicts $db = PSUDatabase::connect('oracle/psc1_psu');
    80. 80. Conflicts $db = PSUDatabase::connect('oracle/psc1_psu'); Trunk $db = PSUDatabase::connect('oracle/psc1_psu/fixcase');
    81. 81. Conflicts $db = PSUDatabase::connect('oracle/psc1_psu'); Trunk $db = PSUDatabase::connect('oracle/psc1_psu/fixcase'); Branch $db = new PSUDatabase('oracle/psc1_psu');
    82. 82. 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
    83. 83. Conflicts .working $GLOBALS['BANNER'] = new PSUDatabase('oracle/psc1_psu'); ======= $GLOBALS['BANNER'] = PSUDatabase::connect('oracle/psc1_psu/fixcase'); .merge-right.r12
    84. 84. 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'
    85. 85. Thanks.

    ×