Upload
adrian-shepherd
View
224
Download
5
Tags:
Embed Size (px)
Citation preview
SOFTWARE REVISION CONTROL WITH SUBVERSIONEvan Dickinson & Andy Huang – 9 March 2011
About revision control
Revision control tracks the changes you make to your code
Professional software developers can’t live without it.
Worth knowing if you write code at all, even if you’re not a “software person”
What it’s good for
Offsite backup Coordinate team work See changes
Undo the change that broke everything Freedom to experiment
You can always revert back to working code Organization
Don’t have to e-mail files, or make lots of copies.
Why you might not use it (for now) Learning takes (a bit of) time You’re using MAX/MSP
Photoshop, Illustrator, and other media files also have low payoff.
Several features work best with text files, not graphics.
But other features are still valuable, even with graphic files.
Plan B: Dropbox At least have a backup & central location
for all code
About Subversion (svn)
There are several tools for revision control subversion is one of them
svn is a command-line tool several graphical front-ends available
Free GUI and free hosting: SmartSVN (GUI – Mac, Windows, and Linux)
Demo. Free version has limited features, but they’re good enough.
Assembla.com (hosting)
Installation
Will be covered later It’s boring
Subversion Concepts
Repository
A server that stores your code Repository records:
Every change that’s made Who made it, when, and why
This is what assembla.com gives you Except they call repositories “spaces.” It’s
the same thing.
Working copy
A copy of the code on your laptop What you edit when you’re writing code You can have several working copies on
your computer Your teammates have their own working
copies
1 Repository & Many Working Copies
Repository(assembla.com server)
Clip art: all-free-download.com
Evan’s Computer
Two working copies, each in different folders
Andy’s Computer
One working copy
Revisions
When you get your code to a good stopping point, snapshot the change in a revision. Share the code with your team Gives a known-good point to go back to
Assembla also calls these “change sets”
Workflow Example
Stop when the code does what you want it to, and you’re ready to share
Step 1: Write your code
Make sure you’re changing what you think you’re changing Keep out temporary/testing changes SmartSVN: “Changes” button. Sometimes called “diff”
Step 2: Review your changes
Brings in newer changes (if any) Keeps you from overwriting your team members’ changes. SmartSVN: “Update” button
Step 3: Update
SmartSVN: “Commit” button Write a message that describes what you
changed
Step 4: Commit the Change
Done: Now your change is in the repository
Demo
Working with other people
Multiplayer Subversion
Workflow: Two people editing different files
Evan’s Working Copy
Repository Andy’s Working Copy
Revision: 5 Revision: 5 Revision: 5
Edit foo.pde Edit bar.pde
Commit revision 6 Revision: 6Repository has Evan’s change to foo.pde
Still at revision 5
Update to revision 6.Andy’s working copy has Evan’s change.
Edit bar.pde some more
Still at revision 6 Revision: 7Repository has Andy’s change to bar.pde
Commit revision 7
Update to revision 7.Evan’s working copy has Andy’s change
Two people editing one file
Best to do this rarely: I’m not saying “don’t” – sometimes you need to Use good communication:
Coordinate who’s doing what Avoid incompatible changes
But when you do: You can’t accidentally overwrite someone else’s
changes When you do an update (to get new changes):
Changes that don’t conflict are brought in automatically
Conflicting changes are highlighted for you to fix (see the section Conflict Resolution)
Demo
Links and Resources
SmartSVN: http://www.syntevo.com/smartsvn/ http://www.syntevo.com/smartsvn/
documentation.html Subversion: http://subversion.apache.org
/ Assembla: http://www.assembla.com Version Control with Subversion
Online book http://svnbook.red-bean.com/
Three steps:1. Sign up for an assembla.com
account2. Install SVN client3. Install SmartSVN
Installation
Assembla.com
Register an account Create a space
You want the free subversion repository The free options are hidden – click to
expand http://www.assembla.com/catalog
Install SVN Client – Mac
Install the MacOS X developer tools SVN is included These are on the MacOS X install DVD Also downloadable from
http://developer.apple.com/technologies/tools/
Is svn already installed? Open Terminal Run: which svn
Install SVN Client – Windows
Download it from: http://sourceforge.net/projects/win32svn/
Install & Configure SmartSVN Download from:
http://www.syntevo.com/smartsvn When you run it for the first time, it will
ask for paths to svnadmin and svnserve Mac:
/usr/bin/svnadmin /usr/bin/svnserve
Windows: c:\program files\subversion\bin\svnadmin c:\program files\subversion\bin\svnserve
Configure SmartSVN (part 2) It starts by offering to set up a repository
for you. Say no. (That offer assumes your repository
already has code in it.) Instead, you want: Import Project Into
Repository This is on the welcome window, or File ->
Import
SmartSVN: Import Project Into Repository
While importing into the repository, you’ll get to a step where it asks you which repository to import to. This is where you tell SmartSVN about your
assembla repository. Add a new repository and fill in the details
Here’s where you find the URL to use
A reminder of what all the buttons do
SmartSVN Overview
Check the selected file
If you select a directory, your action applies to all files in that directory. This is usually what you want.
If you select one file, you only work with that one file. That can be bad if you wanted to commit all your files, but just commit one by mistake.
Refresh
Load the latest data from the repository. Use this to see if there are newer revisions.
Update
Two uses:1. Grab the latest code from the
repository.2. Change the working copy to an
older revision. (This is useful for figuring out if a problem you just found exists in older revisions.)
Commit
Send the contents of your working copy to the repository.
None of the changes you make to your working copy are applied to the repository until you do a commit.
Add
Tells subversion to track changes to the selected file (or directory).
Subversion only tracks the files you tell it to track. Files you don’t add won’t be in your repository.
Remove
Tells subversion stop tracking changes to the selected file (or directory).
Old versions of the file will remain available in the repository. But the file will no longer be in new versions of the repository.
Move (and Rename)Move and/or rename a file.
SmartSVN gets confused if you move/rename files from the Finder (or Windows Explorer)
In this example, we’ve renamed Arm.pde to Leg.pde. Until you do a commit, Arm.pde will show up as “removed.”
Revert
Throws away the changes you’ve made in your working copy. Reverts a file (or directory) back to the way it was when you did an update.
Delete
Deletes a file. Only use this on files that are not tracked by subversion.
Changes
Shows the changes you’ve made in the file.
Annotate
Shows who wrote each line of the file, and when.
Log
Shows the list of revisions
Fix and Graph
These are advanced features. You don’t need them.
Conflict Resolution
Conflicts
Conflicts occur when two people make incompatible changes to one file at the same time.
Usually, it’s OK for two people to change the same file, as long as they change different parts of the file. But if the changes are too close together, they conflict.
Conflicts are rare. But if they happen to you, here’s what to do. If you communicate with your team about
who’s changing what, you can avoid conflicts in the first place.
What conflicts look like
We did an update and – oh no! – there are conflicts.
The new files are:• .mine – the file you edited, as it was before the
update• .r3 – the predecessor for your changes. (That is,
the file as it was before you started editing.) The number will be different in your case.
• .r6 – the newest version of the file.
Fixing conflicts
The left pane shows your file, before the update.
The center pane is the file where you’ll resolve the conflicts. Right now, it has both changes in it, which is no good.
Bring up the conflict solver with Tools -> Conflict Solver
The right pane shows the newest version in the repository.
We got a conflict because two people changed the same line, at the same time.
Fixing conflicts, continued
Use the Take Left and Take Right buttons to choose which code to use.
Fixing conflicts, continued
Here, we used Take Right to copy the changes from the right-hand side to the middle. The conflict is now resolved, and we can save the file and commit it.