Version Control System

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 28

Version Control

Naisan Benatar
On today’s menu...

The problems with lots of code and lots of people


Version control systems
what are they?
how are they used?
centralised versus distributed version control
Features of version control including branching

2
Dealing with Change
• How do you manage your coursework?
• Modifying existing code (using Q1 for a basis for Q2)
• Backing up working code
• Checking if an idea works (Do I use a Hashtable or a
HashMap?)
• Sharing code in group projects

3
(Bad) Solutions
• Copying (Coursework_working.java,
Coursework_tmp.java)
• Copy & Paste code snippets
• Copy entire directories
• Emailing code to people

4
Open Source
You thought coursework was bad?
Linux kernel has thousands of regular
developers, millions of files.
Developers spread over the globe across
multiple time zones

5
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 PC game
Unreal 3 approx 500,000 lines of code

6
Making a mess
The Linux kernel runs on different processors
(ARM, x86, MIPS). These can require significant
differences in low level parts of the code base
Many different modules
Old versions are required for legacy systems
Because it is open source, any one can download
and suggest changes.
How can we create a single kernel from all of this?

7
Not just code!
• A Code Base does not just mean code!
• Also includes:
• Documentation
• Build Tools (Makefiles etc)
• Configuration files

• But NOT a certain type


of file

8
9
Control the process automatically
Manage these things using a version control
system (VCS)
A version control system is a system which
allows for the management of a code base.

10
Details of the process
Files are kept in a repository
Repositories can be local or remote to the user
The user edits a copy called the working copy
Changes are committed to the repository when
the user is finished making changes
Other people can then access the repository to
get the new code
Can also be used to manage files when working
across multiple computers

11
12
Centralised Version Control
• 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.

13
14
Distributed Version Control
• 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!

15
16
More Uses of Version Control
Version control is not just useful for collaborative
working, essential for quality source code development
Often want to undo changes to a file
start work, realize it's the wrong approach, want to get back
to starting point
like "undo" in an editor…
keep the whole history of every file and a changelog

Also want to be able to see who changed what, when


The best way to find out how something works is often to ask
the person who wrote it

17
Branching
• Branches allows multiple copies of the code
base within a single repository.
• Different customers have different requirements
• Customer A wants features A,B, C

• Customer B wants features A & C but not B because his


computer is old and it slows down too much.

• Customer C wants only feature A due to costs

• Each customer has their own branch.

• Different versions can easily be maintained

18
Selecting a VCS
• When choosing a VCS
consider:
• How many files and developers
are likely to be involved in the
project?
• Speed for common operations
(check-in, check-out)
• Is there a server? Does it need
to be powerful?

19
Essential features
Check-in and check-out of items to repository
Creation of baselines (labels/tags)
Version 1.0 released!

Control and manipulation of branching


management of multiple versions

Overview of version history

20
Additional Features (1)
• Change Management:
• Professional software will have bugs. Customers will
find them. How do we know if a bug has been fixed?
• Check-outs of code usually controlled.
• A bug report will identify where the bug is in the code.

• The fixed code (patch) is checked in and linked to bug report

• Hence we can see exactly what changes were made in response


to a specific bug. Good for accountability

21
Additional Features (2)
• Code responsibility & Code audits.
• You stole my code!
• Who is responsible for this module?
• Legal stuff

• Forking – Common with Open source software


• A subset of developers fork off a parent project to
produce a second copy of the project. Reasons vary
but often done to make a more specific version.

• Metrics (Managers only!)


22
Check Outs
• If you want to make a
change the file needs to
be checked out from the
repository
• Usually done a file at a
time.
• Some VCSs will lock
checked out files so only
one person may edit at a
time.
23
Check-In
• When changes are completed the new code is
checked-in.
• A commit consists of a set of checked in files
and the diff between the new and parent
versions of each file.
• Each check-in is accompanied by a user name
and other meta data.
• Check-ins can be exported from the Version
Control system the form of a patch.

24
Merging
• There are occasions when multiple versions of
a file need to be collapsed into a single version.
• E.g. A feature from one branch is required in another

• This process is known as a merge.


• Difficult and dangerous to do in CVS
• Easy and cheap to do it git

25
26
Version Control in action
• I use git for my day to day work. One
developer, lots of code written over 3 years in
multiple languages (C, Python, Java, shell,
awk)
• I need a regular back-up system but work on at
least 3 PCs (Home, work and work linux).

27
Using a git repository
•$ git init
•$ git add <filename>
•$ git commit –a
•$ git branch
•$ git checkout
•$ git push
•$ git pull

28

You might also like