Version Control Systems

Overview

  • Course: ECM2414 – Software Development
  • Topic: Version Control
  • Session: T1: W3-L2
  • Instructor: Prof. Solomon Oyelere
  • Department: Computer Science, University of Exeter

Version Control and Testing Section Overview

Lecture Series (~5 lectures)

  1. Version control: What is it? Why do we need it?
  2. Event handling: Events and listeners
  3. Testing: Basics, Unit testing, JUnit, Mock Objects, Test suites, Test-driven development

Version Control Systems

  • Git (Most popular, distributed)
  • Mercurial (Distributed)
  • Concurrent Versions System (CVS) (Centralized, legacy)
  • Subversion (SVN) (Centralized)

Web-Based Repositories

  • GitHub (Git-based, most popular)
  • Bitbucket (Git and Mercurial)
  • Google Code (Deprecated, historical)

Metaphor: Time Machine

Version control acts as a “project-wide time machine” allowing you to:

  • Travel back to any point in development history
  • See exactly what changed and when
  • Compare different versions of the project

Version Control Theory

Core Definition

Version Control: Records changes over time, allowing you to recall specific versions later.

Fundamental Tool Status

Version control is a fundamental tool in modern software development - not optional, but essential.

Why Use Version Control?

1. Project-Wide ‘Undo Button’

  • Gives development team ability to revert changes
  • Recover from mistakes without losing work
  • Experiment safely knowing you can go back

2. Collaborative Development

  • Allows multiple developers to work on same code base in controlled manner
  • Code no longer lost through overwrites
  • Coordinated changes across team members

3. Change Tracking and Accountability

  • Keeps record of changes and who made them
  • Can find out who has made ‘surprising code’
  • Log commits explaining why changes were made
  • Audit trail for all modifications

4. Multiple Release Support

  • Support multiple releases at the same time
  • No need to freeze development leading up to release
  • Parallel development streams
  • Maintenance branches for older versions

5. Historical Project Examination

  • Project-wide time machine can examine how project looked at particular dates/versions
  • Important when supporting customers with problems
  • Debugging production issues
  • Understanding evolution of features

Version Control Architecture

Repository Structure

Repository: A place to store all project files/documents/directories

Characteristics:

  • Acts as server, usually on safe, secure, reliable machine
  • Central storage for all project assets
  • Backup and recovery capabilities

Client Access

Individual(s) working on project can access material through client version control tools on local machines

Network Requirements

Two models:

  1. Constant network communication required (centralized systems)
  2. Allow local changes offline to resynchronize later (distributed systems)

Repository Models

Two approaches:

  1. Multiple repositories (distributed - Git, Mercurial)
  2. One central master repository (centralized - SVN, CVS)

Version Control Benefits (Detailed)

1. Simultaneous Development Control

  • Changes no longer lost by being overwritten
  • Multiple developers can work simultaneously
  • Merge capabilities for combining changes

2. Responsibility Tracking

  • Easily track down responsibility (praise/blame)
  • Author information for every change
  • Time stamps for all modifications

3. Atomic Commits

  • Modern version control systems have atomic commits
  • All-or-nothing operations
  • Consistency guaranteed

4. Integrated Project Systems

Often part of integrated project source system (e.g., GitHub) providing:

  • Wikis for documentation
  • Bug tracking systems
  • Web application tools
  • Project management features

What Should We Store?

Essential Items

  • Source code (all programming files)
  • Build scripts (compilation and deployment)
  • Project documents (requirements, design, documentation)
  • Configuration files
  • Everything you need if local machines died

What NOT to Store

  • Automatically generated files
    • API documentation (can be regenerated)
    • Compiled binaries (can be rebuilt)
    • Temporary files
    • IDE-specific settings (usually)

Storage Philosophy

Store sources, not products - if it can be regenerated from sources, don’t store it.

Basic Version Control Concept

Fundamental Idea

Developer 1 ←→ Repository ←→ Developer 2
     ↓              ↓              ↓
Local Copy    Master Version   Local Copy

Process:

  1. Check out files from repository
  2. Make changes locally
  3. Commit changes back to repository
  4. Other developers can see updates

Centralized vs Distributed Repositories

Centralized Model (SVN, CVS)

Characteristics:

  • Single central repository
  • As soon as you commit, others can see changes
  • Requires network connection for most operations
  • Server dependency for version history

Process:

Developer A → Central Repository ← Developer B
          (immediate visibility)

Distributed Model (Git, Mercurial)

Characteristics:

  • Multiple repositories (each developer has full copy)
  • Developers must push changes and pull updates
  • Can work offline
  • Full history available locally

Process:

Developer A Repository ←→ Central Repository ←→ Developer B Repository
     (push/pull)                              (push/pull)

Copies vs Versions

Storage Model

Doesn’t just store copies - stores every version that has ever been checked in

Version Numbering

File-Specific Numbering

  • Format: Starting from 1.1
  • Example: version 1.3 of MyObject.java
  • Tracks: Individual file evolution

Repository-Specific Numbering

  • Format: Starting from 0 (or 1)
  • Example: MyObject.java at revision 5
  • Tracks: Global repository state

Version Comparison

File Version:    MyObject.java v1.1 → v1.2 → v1.3
Repository:      Revision 1 → Revision 2 → Revision 3 → Revision 4 → Revision 5

Revision Tags

Purpose

Allow you to provide text for particularly important revisions

Benefits

  • Easier to remember than version numbers
  • More informative than numeric identifiers
  • Meaningful labels for releases

Example Usage

Revision 47 → Tagged as "Release 2.1"
Revision 52 → Tagged as "Bug Fix Release 2.1.1"  
Revision 63 → Tagged as "Beta 2.2"

Common Tag Types

  • Release tags: v1.0, v2.1, Release_3.0
  • Milestone tags: Alpha, Beta, RC1 (Release Candidate 1)
  • Feature tags: DatabaseIntegration, NewUI

Trunk Concept

Definition

Main code base that developers are working on is commonly called the trunk

Challenge Scenario

Problem: At time of new release:

  • Some team members fixing last bugs and evaluating quality
  • Need stability (not worrying about changes affecting future releases)
  • Other developers want to continue new feature development

Poor Solution: Freeze Development

  • Wastes resources (developers idle)
  • Delays future features
  • Inefficient team utilization

Better Solution: Branching

Use branching to allow parallel development streams

Branching

Simple Case (No Branching)

Commit 1 → Commit 2 → Commit 3 → Commit 4
                    (Linear history)

Complex Case (With Branching)

                    Commit 3 → Commit 4 (Feature Branch)
                   ↗
Commit 1 → Commit 2
                   ↘  
                    Commit 5 → Commit 6 (Main Branch)

Branch Characteristics

  • Almost like having two separate repositories
  • Each branch has its own history
  • Tracks changes independently
  • Can diverge significantly

Branch Use Cases

  • Feature development (isolated from main code)
  • Bug fixes (stable branch for releases)
  • Experimental work (without affecting main line)
  • Release preparation (stabilization branch)

Forking

Definition vs Branching

Forking is somewhat different from branching

Traditional Meaning

  • Independent branch of development
  • Project fork historically means schism in development team
  • New development team working on new direction derived from old
  • Permanent divergence from original project

Modern Social Coding (GitHub)

  • Recent VCS such as GitHub allows more social coding
  • Expressly encourages this kind of development
  • Forking becomes collaboration mechanism
  • Pull requests to merge changes back

Fork vs Branch

AspectForkBranch
OwnershipIndependent projectSame project
IntegrationMay never merge backIntended to merge
PurposeDifferent directionTemporary isolation
CollaborationBetween projectsWithin project

Merging

Purpose

Version control systems allow you to “merge back” changes made in branches to main trunk

Benefits

  • Bug fixes in release branch can be used to fix trunk source too
  • Feature development can be integrated back
  • Parallel work streams can be combined

Merge Process

Main Branch:    A → B → C ← ← ← Merge Point
                         ↑
Feature Branch:         D → E (changes merged in)

Merge Types

  • Fast-forward merge: Simple linear integration
  • Three-way merge: Combining divergent branches
  • Conflict resolution: Manual intervention when changes clash

Locking Strategies

The Problem

What happens if two (or more) people change the same file at the same time?

Strict Locking

Characteristics:

  • Only one person can change a file at any one time
  • Must acquire lock before editing
  • Prevents conflicts completely

Benefits:

  • No merge conflicts
  • Guaranteed exclusive access

Drawbacks:

  • Blocks collaboration
  • Can create bottlenecks
  • Forgotten locks prevent others from working

Optimistic Locking

Characteristics:

  • All files can be changed simultaneously
  • If changed in repository since last checkout, local copy needs updating before commit
  • Conflicts resolved during commit process

Benefits:

  • Better collaboration
  • No blocking of development
  • Faster development cycle

Drawbacks:

  • Merge conflicts must be resolved
  • More complex workflow

Implications of Optimistic Locking

Conflict Resolution Responsibility

Version control system doesn’t know what you want - leaves it up to you to sort out conflicts

Typical Workflow

  1. Make changes to local file
  2. Attempt to commit
  3. If file changed since last update → commit fails
  4. Must update local copy first
  5. Resolve any conflicts
  6. Then commit successfully

Example Scenario

Developer A: Modifies line 15 of MyClass.java
Developer B: Also modifies line 15 of MyClass.java
             
When B tries to commit:
→ Error: "File has been modified since your last update"
→ B must update, resolve conflict on line 15, then commit

Binary Files and Locking

Binary File Challenges

Most version control systems detect when file is binary (vs text-based like Java file) and mark it as non-mergeable

Conflict Resolution for Binary Files

  • Conflicts must be merged through manually merging the two files
  • No automatic text merging possible
  • Choose one version or recreate from scratch

Lock Prevention

  • Can usually set file to have lock preventing this problem
  • Explicit locking for binary assets
  • Prevents concurrent editing of unmergeable files

Lock Release

Typically when you commit a file or directory, all locks are released that you are holding

Binary File Examples

  • Images (.jpg, .png, .gif)
  • Documents (.doc, .pdf)
  • Executables (.exe, .jar)
  • Audio/Video files

Good Practices

1. Use Version Control Tools

Even if you have direct access to server directory where repository is stored, always use version control copying, renaming, and deletion tools

Why: Direct file system operations bypass version control tracking

2. Establish Secure Access

Before you start, establish effective and secure access to your repository

Considerations:

  • Authentication mechanisms
  • Authorization levels
  • Network security
  • Backup strategies

3. Project Organization

Each project you develop should be in a distinct directory in repository

Benefits:

  • Clear separation of concerns
  • Independent versioning
  • Easier project management

4. Subcomponent Management

Subcomponents that can be developed in isolation and shared should be in their own projects

Examples:

  • Utility libraries
  • Common frameworks
  • Reusable components

5. Store More Than Code

Don’t just use it for code - include all project assets

Additional items:

  • Documentation
  • Configuration files
  • Build scripts
  • Test data
  • Project specifications

Exercise: Version Control Concepts

Question: Choose the correct statement about version control:

All Statements Are Correct

A. Version control is a fundamental tool in modern software development, with which you can go back to previous states of your development, so it provides a project-wide undo button.

  • ✅ Correct: Core benefit of version control systems

B. Version control can be a centralized system, or a distributed system.

  • ✅ Correct: Two main architectural approaches exist

C. Version control allows you to see who has done what and makes it much easier to deal with some surprising code.

  • ✅ Correct: Change tracking and accountability features

D. Class files of Java programs need to be stored in the version control system.

  • ❌ Incorrect: Class files are generated artifacts and should NOT be stored in version control

Explanation for D: Class files (.class) are compiled output that can be regenerated from source code (.java files). Storing generated files leads to:

  • Repository bloat
  • Merge conflicts on binary files
  • Inconsistency between source and compiled versions

Key Takeaways

Version Control Benefits

  1. Project-wide undo capability for mistake recovery
  2. Collaborative development without conflicts
  3. Change tracking and accountability
  4. Multiple release support simultaneously
  5. Historical examination of project evolution

Architecture Choices

  1. Centralized vs Distributed based on team needs
  2. Repository organization affects project management
  3. Branching strategies enable parallel development
  4. Locking strategies balance collaboration and conflict prevention

Best Practices

  1. Use version control tools exclusively for repository operations
  2. Store sources, not products (avoid generated files)
  3. Organize projects logically in repository structure
  4. Establish secure access before beginning work
  5. Include all project assets, not just source code
  1. Distributed systems (Git) increasingly popular
  2. Social coding platforms (GitHub) enhance collaboration
  3. Integration with other development tools
  4. Automated workflows and continuous integration

Version Control in Development Workflow

Daily Usage Pattern

  1. Start day: Pull latest changes from repository
  2. Make changes: Edit files locally
  3. Test changes: Ensure functionality before committing
  4. Commit changes: Add to version control with descriptive message
  5. Push/synchronize: Share changes with team

Team Collaboration

  1. Branching strategy for feature development
  2. Code reviews before merging to main branch
  3. Conflict resolution procedures
  4. Release management through tagging

Summary

Version control is essential infrastructure for modern software development, providing:

  • Safety net for development mistakes
  • Collaboration framework for teams
  • Historical record of project evolution
  • Release management capabilities

Understanding different approaches (centralized vs distributed) and best practices enables effective use of version control systems in software projects.

Next lecture: Event Handling (Events and Listeners)


Tags

versioncontrol git svn softwaredevelopment collaboration branching merging repository sourcecontrol teamdevelopment sdlc