21
1 Subversion Kate Hedstrom April 2007

Subversion

Embed Size (px)

DESCRIPTION

Subversion. Kate Hedstrom April 2007. Version Control Software. System for managing source files For groups of people working on the same code When you need to get back last week’s version In the old days, there was SCCS and RCS for file-wise management Then came CVS - PowerPoint PPT Presentation

Citation preview

Page 1: Subversion

1

Subversion

Kate HedstromApril 2007

Page 2: Subversion

2

Version Control Software

• System for managing source files– For groups of people working on the same code

– When you need to get back last week’s version

• In the old days, there was SCCS and RCS for file-wise management

• Then came CVS– Works with whole directory trees– Has a network option for remote access

• Newest is SVN, which attempts to fix the shortcomings in CVS

Page 3: Subversion

3

Getting Started With SVN

• Tell it where the archive is with a URL:

• Mine is in nanook’s /archive, visible to Sun and iceflyer

• For a new archive:

file:///local/path orhttp://host/path

% svnadmin create /local/path

Page 4: Subversion

4

Main svn commands

• import - bring sources into the repository

• checkout - get sources out of the repository

• commit - check in changes• update - get changes from repository• status - find out which files would change on commit

• diff - find out what changed• help

Page 5: Subversion

5

Example

• The svn people advise setting up a directory tree with subdirectories– trunk– tags– branches

• Your actual code goes in trunk

Page 6: Subversion

6

% ls /tmp/cppbranches tags trunk# import whole directory% svn import /tmp/cpp \ file:///local/path -m “initial import”% rm -rf /tmp/cpp# want to be working in checked-out copy% svn checkout \ file:///local/path/cpp/trunk cpp% cd cpp[make some changes]% svn commit

Page 7: Subversion

7

# on iceflyer% svn checkout <URL> roms% cd roms[make some changes]% svn commit

# on cygnus% svn checkout …% cd roms% svn update% make

Coordination

• Coordinate code on multiple systems• Coordinate between multiple programmers

• Can be common version or different branches

Page 8: Subversion

8

Updates

• An update when two people have changed things can involve:– No conflict because changes are in different

places– Conflict because two different changes to the

same region in the code

• If there is a conflict this must be resolved by human intervention

• One option is to revert (undo)

Page 9: Subversion

9

Other svn commands• add - add a new file or directory to svn control

• delete - no longer need a file• move - rename a file or move to new location

• merge - merge changes from another branch

• info - find URL used• copy - make branches and tags• switch - switch working directory to a different branch

Page 10: Subversion

10

Revision Numbers

• svn uses a database to store the files• The whole project as one revision number across the whole project to describe that snapshot

• Can see the numbers with “svn log”• This is different from CVS, which keeps a different number for each file (uses filewise RCS for repository)

• Every commit creates a new revision number

Page 11: Subversion

11

• Branch can be just for one or a few files or the whole ROMS tree

Branches

Page 12: Subversion

12

Tags

• Tags are handled like branches• Create a working version that goes together and make a branch in the tags directory with the name of the tag (release_1.0, say)

Page 13: Subversion

13

ROMS Example

• ROMS comes from a read-only repository:

svn checkout <URL> hernan_roms• Make own repository where that version is the trunk– Copy it to another location without the .svn files– Import it into your repository

Page 14: Subversion

14

• Now make a branch for your version: svn copy <URL1> <URL2>• These have to be in the same repository

• It is currently a copy of the main ROMS code - edit it with your changes and check it back in

svn checkout <URL2> Edit… svn commit

Page 15: Subversion

15

• So, Hernan has made some changes, what now?

• Go to your copy of his code from his repository:

svn update• Make note of files that were added and deleted

• Copy to the trunk part of your repository:

tar cvf - --exclude .svn | (cd ../roms_trunk; tar xvf -)

Page 16: Subversion

16

• In your trunk directory, add and delete the files you noted before:

svn add new files… svn delete old files…• Check status, then check in: svn status svn commit• Make note of the version number

Page 17: Subversion

17

• Doing the actual merge - in the directory for your branch (URL2):

svn merge -r 41:45 <URL1>• Resolve conflicts, if any• Check in the update, making note of the revision numbers and <URL1>

svn ci -m “merge from -r 41:45 <URL1>”

Page 18: Subversion

18

ROMS Summary

• Each directory has .svn files pointing to its URL

Page 19: Subversion

19

Conflicts

• If there is a conflict, svn will provide you with four files:– The original file (filename.mine)– The older file from the trunk (filename.r41)– The newer file from the trunk (filename.r45)– A merge attempt (filename)

• The merge failures will look something like:

Page 20: Subversion

20

Clean code before <<<<<<< .mine My code ======= New code >>>>>>> .r45 Clean code after• Once you’ve cleaned up the mess, tell svn you’re ready:

svn resolved filename• This will cause svn to delete the extra files and allow a commit to take place

• You can instead toss your changes with: svn revert filename

Page 21: Subversion

21

Learn more

• Version Control with Subversion, by Collins-Sussman et al., 2004, O’Reilly

• Online at http:svnbook.red-bean.com/• svn help