Version Control and Subversion (SVN) : Slides Created by Marty Stepp, Modified by Josh Goodwin
Version Control and Subversion (SVN) : Slides Created by Marty Stepp, Modified by Josh Goodwin
Lecture 9
Version control and Subversion (svn)
1
Working Alone
• Ever done one of the following?
Had code that worked, made a bunch of changes and saved it, which broke the
code, and now you just want the working version back…
Accidentally deleted a critical file, hundreds of lines of code gone…
Somehow messed up the structure/contents of your code base, and want to just
“undo” the crazy action you just did
Hard drive crash!!!! Everything’s gone, the day before deadline.
• Possible options:
Save as (MyClass-old.java)
• Ugh. Just ugh. And now a single line change results in duplicating the entire file…
RAID to protect your files
• That’s one pricey laptop
2
Working in teams
Whose computer stores the "official" copy of the project?
• Can we store the project files in a neutral "official" location?
Wiki’s
• Wiki’s are all about version control, managing updates, and allowing
rollbacks to previous versions
4
Software Version control
• Many version control systems are designed and used especially for
software engineering projects
examples: CVS, Subversion (SVN), Git, Monotone, BitKeeper, Perforce
not particular to source code; can be used for papers, photos, etc.
• but often works best with plain text/code files
5
Repositories
• repository: Central location storing a copy of all files.
check in: adding a new file to the repository
update: downloading the latest versions of all files that have been
recently committed by other users
6
Repository Location
• Can create the repository anywhere
Can be on the same computer that you’re going to work on, which might
be ok for a personal project where you just want rollback protection
7
Subversion
command description
svnadmin make administrative changes to an SVN repository
svn interact with an SVN repository
8
SVN commands
command description
svn add files schedule files to be added at next commit
svn ci [files] commit / check in changed files
svn co files check out
svn help [command] get help info about a particular command
svn import directory adds a directory into repo as a project
svn merge source path merge changes
svn revert files restore local copy to repo's version
svn resolve source path resolve merging conflicts
svn update [files] update local copy to latest version
others: blame, changelist, cleanup, diff, export, ls/mv/rm/mkdir,
lock/unlock, log, propset
9
Setting up a repo
• on attu, create the overall repository:
$ svnadmin create path
10
Adding files to a repo
• on your computer, set up a local copy of the repo
$ svn co svn+ssh://attu.cs.washington.edu/foldername
or, if you're setting up your local copy on attu as well:
$ svn co file:///homes/iws/username/foldername
after checkout, your local copy "remembers" where the repo is
• now copy your own files into the repo's folder and add them:
$ svn add filename
common error: people forget to add files (won't compile for others)
• Exercise: check out the repository, add some files, and commit them
12
Shell/IDE integration
Linux:
NautilusSVN
Windows:
TortoiseSVN
Eclipse:
Subclipse
13
TortoiseSVN
• Available at http://tortoisesvn.net/
• Exercise: Check out our repository, modify a file, add a file, and
commit our changes
14
What’s actually going on?
• Take a look inside the svn project folder…
Where the heck are our committed files?
Take a look at the readme…
15
Merging and conflicts
• merge: Two sets of changes applied at same time to same files
happens when two users check out same file(s), both change it, and:
• both commit, or
• one changes it and commits; the other changes it and does an update
16
Branches
• branch (fork): A second copy of the files in a repository
the two copies may be developed in different ways independently
given its own version number in the version control system
eventually be merged
trunk (mainline, baseline): the main code copy, not part of any fork
17
Learn what you need
• Creating branches and using merge tools are usually more than you
need for any curriculum projects
Personally not a fan of the conflict resolution tools – I’ll usually just
back up my conflicted file, update so I now have the current version,
then manually merge my changes with the updated files
• But, they are definitely used in industry, and you should at least
know about them
18
Another view: Git
• Git is another popular version control system.
• Main difference:
SVN:
• central repository approach – the main repository is the only “true” source, only the main
repository has the complete file history
• Users check out local copies of the current version
Git:
• Distributed repository approach – every checkout of the repository is a full fledged
repository, complete with history
• Greater redundancy and speed
• Branching and merging repositories is more heavily used as a result
19
Wrap-up
• You *will* use version control software when working on projects,
both here and in industry
Rather foolish not to
Advice: just set up a repository, even for small projects, it will save you
time and hassle
20