Version Control

Steven J Zeil

Last modified: Sep 14, 2017


Version control (a.k.a. version management is concerned with the management of change in the software artifacts being developed.

In this lesson we look at the kind of practical problems that arise during software development and that can be addressed by proper version control.

1 Issues in Version Control

The issues addressed by version control are:

2 Background - Changing the Code Base


One of the earliest Unix text editors, ed applies a series of editing commands like ‘a’ to append to th end of a file, ‘i’ to insert a line at the current location, ‘d’ to delete the current line, etc.


diff compares two files line by line, listing the differences between them.

diff --ed file1 file2 > file12.diff
echo w file2 >> file12.diff
#  many days later...
ed file1 < file12.diff

would “rebuild” file2 from file1 and the diff.


patch takes a slightly more sophisticated approach to the idea of applying a diff output to a file

diff file1 file2 > file12.diff
patch file1 file12.diff

2.1 Integrating Changes

Suppose that we have two patch files created from the same base file file1

patch -o file2a file1 patchA
patch -o file2b file1 patchB

Change integration is the problem of combining both sets of changes to form a desired file file2.

Two-way Change Integration

patch -o file2a file1 patchA
patch -o file2b file1 patchB

How do we know which patched file is “correct”, or whether we need some combination of the changes?

Two-way procedure:

  1. Compare file2a and file2b
  2. Wherever the two are different, prompt the human to select the desired change.

Three-way Change Integration

Takes the base file into account as well as the two changed files.

patch -o file2a file1 patchA
patch -o file2b file1 patchB

Three-way procedure:

  1. Compare file1 and file2a, then file1 and file2b
  2. Any lines that differ from file1 in only one of the two other files can be applied automatically.
  3. Wherever both file2a and file2b are different from file1, prompt the human to select the desired change.
    • This is called a conflict.

3 Approaches and Tools

Version Control Systems

If we could extend patch multiple files at once, we could, in theory, patch an entire software system to move it from version 1 to version 2, then patch it again to move to version 3, etc.

Approaches and Tools