230 likes | 351 Views
An Crash Course in Version Control with Subversion. Checking Out. Repositories can be local or remote. Remote repositories accessed via WebDAV are ideal for collaboration
E N D
Checking Out • Repositories can be local or remote. Remote repositories accessed via WebDAV are ideal for collaboration • $ svn checkout \https://svn.crew/svn/general/A READMEA benderA bender/LICENSEA bender/READMEA bender/README.crew...
Checking Out, cont. • Check out just subdirectories:$ svn co https://svn.crew/svn/general/rtbot/libA libA lib/bot_msg.pl... • Check out the repository at a specific revision:$ svn checkout -r 271 https://... • Keeping your local copy up-to-date:$ svn update
What I Got • $ lsREADME bender/fortune/ handbook/hostpool/ ircd/jabber/ ldap/...
Willy-nilly! • No locks, so go nuts!$ rm -rf bender$ mkdir blorg$ vim README$ /dev/random | head \> ldap/important_info
Wha’ happened? • $ svn statusM README! bender? blorg? ldap/important_info
Removing • $ svn rm benderD bender • $ svn status...D bender... • bender and subdirectories won’t be deleted until commit
Oops, I want that! • Revert a file or directory to the state when it was checked out • $ svn revert -R benderReverted ‘rtbot’Reverted ‘rtbot/README’Reverted ‘rtbot/lib’...
Adding Things • $ vim file.txt$ svn add file.txt • $ mkdir testdir$ svn add testdir • If you already have stuff in the directory, Subversion will do add the items recursively • If you have un-added stuff in the already-added directory, Subversion will simply tell you the directory is already under version control • $ svn mkdir testdir • $ svn mkdir https://.../testdir
Moving Things • $ mv file.txt file2.txt$ svn status! file.txt? file2.txt • $ svn mv file.txt file2.txt$ svn statusD file.txtA + file2.txt • CVS has no mv command — you have to hack the repository to save history
Copying Things • $ cp file.txt file2.txt$ svn status? file.txt • $ svn cp file.txt file2.txtA file2.txt$ svn statusA + file2.txt • “cheap copy”
Cheap, you say? • Not hogwash! Copying simply creates a new stub in the repository, rather, a pointer to another file in the repository at a certain revision • Easily create tags that mark an entire revision of the repository, or part thereof • $ svn cp project/trunk project/tags/1.2 • $ svn cp https://../trunk https://../1.2
Making a Difference • $ svn diff file.txt... • $ svn diff -r 123:124 file.txt... • Subversion also does binary diffs
Commitment • $ svn commit(in $EDITOR:)I did stuff--This line, and those below, will be ignored--D file.txtA + file2.txt • $ svn ci -m ‘I did stuff’
Simple Merging • I edit the same file as Muncus. He checks in before I do. I try to commit my changes:$ svn ci -m ‘added info’Sending file.txtsvn: Commit failed (details follow):svn: Out of date: ‘file.txt’ ...$ svn upG file.txt$ svn diff file.txt...
Not-So-Simple Conflicts • Muncus and I edit the same lines of the same file.$ svn upC file.txt$ lsfile.txt file.txt.minefile.txt.r2 file.txt.r3
Conflict Files • file.txt.mine — my changes, formerly just file.txt • file.txt.r2 — the previous revision’s copy, before Muncus’ change • file.txt.r3 — the latest revision’s copy, after Muncus’ change • file.txt — line-by-line conflict listings
Line-by-Line Conflict Files • This line didn’t change.<<<<<<<<<<<<<< .mineDon’t touch this line.==============muncus 0wnz j00!!!11!>>>>>>>>>>>>>> .r3This line didn’t change, either.
Resolving Conflicts • Fix the file • Fix conflicts by hand using editor & conflict markers • Use one of the revision files • Revert the file • Mark the file as OK • $ svn resolved file.txt • Shake hands
Handy Commands • $ svn help • $ svn help command • $ svn cleanup • $ svn cat -r 277 file.txt • $ svn blame file.txt • $ svn export https://.../
Properties • $ svn propset svn:keywords “Id” file.txt$ vim file.txtThis is version $Id$$ svn ci -m ‘added ID thingey’$ cat file.txtThis is version $Id: file.txt 277 ... ian $
Ignoring Ignorables • Sometimes the output of svn status gets annoying if you’re editor makes swap files, or you don’t care about object files... • $ svn propedit svn:ignore .*.class.*.swp • Doesn’t descend into subdirs
Where to Go From Here • Roll your own repository:$ svnadmin create myrepos$ svn co file://$HOME/myrepos stuff • Read the Subversion Book • http://svnbook.red-bean.com/