Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 32

Week 15 Version Control

Richard Smith
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!!!! Everythings gone, the day before deadline.

Possible options:
Save as (HelloWorld_v1.c, HelloWorld_v2.c,HelloWorld_v3.c)
No very efficient! Now a single line change results in duplicating the entire file
RAID to protect your files
Thats one pricey laptop
Working in teams
Whose computer stores the "official" copy of the project?
Can we store the project files in a neutral "official" location?

Will we be able to read/write each other's changes?
Do we have the right file permissions?
Lets just email changed files back and forth! Yay!

What happens if we both try to edit the same file?
Bill just overwrote a file I worked on for 6 hours!

What happens if we make a mistake and corrupt an
important file?
Is there a way to keep backups of our project files?

How do I know what code each teammate is working on?
4
Big code bases
Operating systems code
Win 95 approx 5 million lines of code (1995)
Linux kernel 2.6.37 14 million lines of code (2011)
Modern(ish) PC game
Unreal 3 approx 500,000 lines of code
Rome 2 Total war 3 millions lines of code (James
Russell, lead developer 2013)
Version Control
version control system: Software that tracks and
manages changes to a set of files and resources.

You use version control all the time
Built into word processors/spreadsheets/presentation
software
The magical undo button takes you back to the version before
my last action

Wikis
Wikis are all about version control, managing updates, and allowing
rollbacks to previous versions
Version Control
Many version control systems are designed and used
especially for software engineering projects
examples: CVS, Subversion (SVN), Git, Monotone, BitKeeper, Perforce


helps teams to work together on code projects
a shared copy of all code files that all users can access
keeps current versions of all files, and backups of past versions
can see what files others have modified and view the changes
manages conflicts when multiple users modify the same file

not particular to source code; can be used for papers, photos, etc.
but often works best with plain text/code files
Centralised Version Control
CVS, SVN
A single server holds the code base
Clients access the server by means of check-
in/check-outs
Examples include CVS, Subversion, Visual Source
Safe.
Advantages: Easier to maintain a single server.
Disadvantages: Single point of failure.



7
Distributed Version Control
Git, Perforce
Each client (essentially) holds a complete
copy of the code base.
Code is shared between clients by
push/pulls
Advantages: Many operations cheaper. No
single point of failure
Disadvantages: A bit more complicated! Not
as easy to manage

8
Centralised
Server holds a centralised repository

Clients have a revision
Centralised
Centralised
Submit
Centralised
Centralised
Get Latest Revision
Centralised
Modify/add/remove files
Centralised
Submit
Centralised
Get Latest Revision
Distributed
All machines have a full copy of the repository

Repositories can be cloned

Repositories can be pushed to and pulled from other machines
Distributed
Create a local repo
Locally commit changes
git init
// Add files to directory
git add *
git commit a m <description>
Distributed
Clone a remote repo
git clone git@github.com:example.git
Distributed
Locally commit changes
git commit a m <description>
Distributed
Push changes to other repos
git push
Distributed
Pull changes from other repos
git pull
Version control secondary mission
Primary mission of version control
software is to track the various versions of
files over time
Secondary mission can be seen as
enabling collaborative editing and sharing
of data
Different systems use different strategies
File Handling
At first glance, the client-
server architecture of a
version-control system
looks much like a typical
file server.

So why do we need
version control?
File Sharing Issues, 1
Assume your project has 15 developers:
Each developer wants to make 1 change and
must communicate this change to all other
developers.
What are the total number of interactions
that must occur?
C(15, 2) = N(N 1)/2 = 15(14)/2 = 105.
Thats a lot of information to track!

File Sharing Issues, 2
Image: Version Control with Subversion
The problem is that
users are stepping on
each others feet!
Approach 1: Lock, Modify, Unlock
Image: Version Control with Subversion
1. Locking may cause
administrative
problems.
2. Locking may cause
unnecessary
serialization.
3. Locking may create a
false sense of security.


Approach 2: Copy-Modify-Merge
Image: Version Control with Subversion
Sounds chaotic, but in
practice, runs extremely
smoothly.

If Sally publishes her
version first then when
Harry attempts to submit his
changes he gets an out-of-
date error
Approach 2: Copy-Modify-Merge
Harry has to merge his
version with the current
version in the repository.
This merged version can
then be published and
downloaded by Sally.

This approach works on
Git and SVN
Conflicting Changes
What happens if Harry and Sallys changes DO overlap?
int imaginaryFunction (int a, int b) Master copy
float imaginaryFunction (int a, int b) Sallys copy
int imaginaryFunction (int a, float b) Harrys copy
Say Sally uploaded her changes first and then Harry tries to upload his.
Harrys file needs to be flagged as being in conflict with Sallys. Harry will be able to see
all of the conflicts that have arisen
There is no way of automating the decision as to how to resolve a conflict
There should be COMMUNICATION between the two as to how to resolve it!
Distributed Workflows
Integration Manager Workflow
The project maintainer pushes to their public repository.
A contributor clones that repository and makes changes.
The contributor pushes to their own public copy.
The contributor sends the maintainer an e-mail asking them to pull changes.
The maintainer adds the contributors repo as a remote and merges locally.
The maintainer pushes merged changes to the main repository.
Distributed Workflows
Dictator and Lieutenants Workflow
Regular developers work on their topic branch and rebase their work on top of
master. The master branch is that of the dictator.
Lieutenants merge the developers topic branches into their master branch.
The dictator merges the lieutenants master branches into the dictators master
branch.
The dictator pushes their master to the reference repository so the other
developers can rebase on it.

You might also like