Abstract
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.
The issues addressed by version control are:
History
How has the software changed since date-or-version-number? Who made those changes? Why were they made? Can we go back?
Exploration
Collaboration
ed
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
diff compares two files line by line, listing the differences between them.
Differences are listed as a series of line replacements, insertions, and/or deletions
Can emit differences as ed commands:
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
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
Allows a variety of different diff variants
Can detect if file1 has already been changed so that the line numbers and other info in the patch file file12.diff are no longer accurate.
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:
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:
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
Local version control systems manage history by setting aside directories on the same file system where the software under control is housed.
Centralized version control systems keep the system history at a centralized location accessible via the network.
Developers check out a copy of the current (or a desired older) version of the software onto their own machines.
Distributed version control systems allow developers to keep the full system history on their own machines.
A central location may hold a base copy for management/distribution purposes, but this is not required.