Safekipedia

Version control

Discoverer · ages 10+Adapted from Wikipedia
Example history graph of a revision-controlled project, with the trunk in green and the branches in yellow; the graph is not a tree, however, due to presence of merges (the red arrows).

Version control, also called revision control, source control, or source code management, is a practice used in software engineering. It involves controlling, organizing, and tracking the different versions of computer files over time. These files are mainly source code text files, but the practice can be used with almost any type of file.

Version control is a part of software configuration management. A version control system is a software tool that does this work automatically. Some other programs also have version control built in, such as word processors, spreadsheets, collaborative web docs, and content management systems, like the page history on Wikipedia.

With version control, you can look at older versions of a file and revert it to a previous version.

"Source control" also leads to this article. For other uses in medicine and the environment, see Source control (disambiguation). "Revision control system" also leads here, but for the software tool, see Revision Control System. This topic is not to be confused with Change control.

Overview

As teams build software, they often have several versions of the same program in use at once, and different developers may work on different versions at the same time. Bugs or features are often found only in certain versions, because fixing some problems can introduce others. To find and fix bugs, it is very important to be able to get and run different versions and see which ones have the problem. Sometimes two versions are worked on at the same time: one with bugs fixed but no new features (branch), and another where new features are added (trunk).

The simplest approach is to keep many copies of the program and label them, and many large software projects have done this. It can work, but it is inefficient because many nearly identical copies must be kept, and it often leads to mistakes. Systems that automate some or all of this process, called revision control, were developed to solve these problems. They abstract most steps, which means they hide them from ordinary users. Revision control can also track changes to configuration files on Unix systems. Each version of a file is numbered, is linked to a timestamp and the person who made the change, and can be compared, restored, and sometimes merged.

History

See also: Comparison of version control software § History and adoption

IBM's OS/360 IEBUPDTE software update tool dates back to 1962 and may be an early ancestor of version control tools. Two source management and version control packages, The Librarian and Panvalet, were used heavily on IBM 360/370 computers.

In 1972, a complete system for controlling source code, the Source Code Control System (SCCS), was started, again for OS/360. Its user manual, published on December 4, 1975, suggested that it was the first deliberate revision control system. The Revision Control System (RCS) followed in 1982. Later, Concurrent Versions System (CVS) added network and team development features to RCS. After CVS, Subversion became the leading successor, followed by the rise of distributed version control tools such as Git.

Structure

Revision control keeps track of changes to a set of data over time. Often each file or document is tracked on its own, but this causes problems when files are renamed, split, or merged. Some systems, such as Git, track changes to all the data as a whole. This is less simple for small changes but makes complex changes easier. When data is checked out and changed, the change is not usually shown right away in the repository. It must be checked in or committed. A copy kept outside revision control is called a "working copy."

Example history graph of a revision-controlled project, with the trunk in green and the branches in yellow; the graph is not a tree, however, due to presence of merges (the red arrows).

When many people work on the same data, they create branches, which leads to merging. For simple shared documents, this can be avoided with file locking or by not editing the same document at the same time. Some systems use one main repository, while distributed revision control has no single main one. Using ideas from graph theory, the history is often pictured as a main line with branches. The real shape is a directed acyclic graph, but a "tree with merges" is a useful picture. A merge happens when a new version combines changes from more than one earlier version, and it can be hard when the changes overlap.

Specialized strategies

Engineering revision control grew out of formal processes for tracking changes to early blueprints or bluelines. This allowed people to return to an earlier version of a design when they reached a dead end. A revision table kept track of the changes, and revision clouds highlighted the edited areas of a drawing.

Version control is also common in business and law. "Contract redline" and "legal blackline" are among the earliest forms of revision control and are still used today. The most advanced methods are beginning to track changes to CAD files electronically (see product data management), replacing older manual methods. Game studios often work with large files and teams across different fields, so they use version control systems that handle large files, lock files while someone edits them, and sync quickly. Common tools include Perforce and newer cloud-based systems.

Source-management models

Main article: Atomic commit

Traditional revision control systems use a centralized model, where all the work happens on a shared server. If two developers try to change the same file at the same time, they may overwrite each other's work. Centralized systems handle this in one of two ways: locking files or version merging. An operation is atomic if the system stays in a consistent state even when it is interrupted. A commit, which makes a group of changes final and available to all users, is usually the most important operation of this kind. Concurrent Versions System lacks atomic commits.

Main article: Merge (version control)

The simplest way to prevent concurrent access problems is to lock files so only one developer at a time can change the central repository copy. Locking can protect against difficult merge conflicts, but files may be left locked and forgotten. Most systems let developers edit the same file at once. The first developer to check in changes always succeeds, and later changes can be merged in. Merging works best for simple text files, since merging image files may not produce an image at all. Labels, tags, and baselines all mark a snapshot of a project, and "baseline" is the term most often used in formal configuration management (see also baseline).

Distributed revision control

Main article: Distributed version control

Distributed revision control systems (DRCS) take a peer-to-peer approach, unlike the client–server approach of centralized systems. Instead of one central repository that everyone syncs with, each peer's working copy of the codebase is a bona-fide repository. Changes are shared by exchanging patches (change-sets) from peer to peer. This means there is no canonical, reference copy of the codebase by default, only working copies.

Common tasks, such as commits, viewing history, and reverting changes, are fast because there is no need to talk to a central server. Communication is only needed when pushing or pulling changes to or from other peers. Each working copy also works like a remote backup of the codebase and its change-history, which protects against data loss.

Best practices

Following best practices is needed to get the full benefits of version control. The best practices can vary depending on the version control tool and the field where it is used. In software development, the generally accepted best practices include making small changes and making commits that involve only one task or fix. Commits should contain only code that works and does not knowingly break existing features. Other good habits are using branches to finish new features before release, writing clear commit messages that explain what, why, and how, and using a consistent branching strategy.

Other software development practices, such as code review and automated regression testing, can help people follow version control best practices.

Costs and benefits

The costs and benefits of version control depend on the tool chosen and the field where it is used. This section focuses on software development, where version control is widely used. Using version control costs money for the software license, and it also takes time and effort. People must understand the ideas behind it, learn how to use the chosen software, and fit good habits into how the team already builds software. Managers may need to keep everyone following these habits so the team gets real benefit.

The main benefit is keeping a history of changes, so a developer can easily undo them and feel free to experiment without fear of breaking existing code. Branching helps with deployment and release management, and makes it simpler to manage patches across stages like development, testing, and production. Records of who changed what, when, why, and how can reduce damage and help find problems. Version control also makes finding mistakes easier, since a test run on different versions can show which change caused a bug. It helps teams work together by spotting conflicting changes, so developers need less coordination, and clear notes and labels help them communicate.

Integration

Some of the more advanced tools for tracking changes offer many other features. These let them work closely with other tools and with the ways software is built.

Plugins are often available for IDEs such as Oracle JDeveloper, IntelliJ IDEA, Eclipse, Visual Studio, Delphi, NetBeans IDE, Xcode, and GNU Emacs (via vc.el). Advanced research prototypes generate appropriate commit messages.

Common terminology

Main article: Delta compression

Main article: File locking

Main article: Baseline (configuration management)

Main article: Branching (revision control)

Main article: Commit (revision control)

Main article: Merge (revision control)

Main article: Revision tag

Main article: Trunk (software)

Terms can vary from one system to another. A baseline is an approved version of a file that later changes can be made to; see baselines, labels and tags. A branch starts when a set of files is split at one point in time, so two copies can grow in different ways. A change (or diff) is one specific edit to a file. A commit saves the changes from your working copy back to the repository, along with a short commit message that explains the change. On many systems with atomic multi-change commits, a change list names all the changes saved in one commit. A checkout makes a local working copy from the repository. Export gets the files without the version-control information, and import copies a folder into a repository for the first time. The head is the most recent commit. Blame finds who last changed a particular line. A tag marks an important snapshot in time, often with a meaningful name.

A conflict happens when different people change the same document and the system cannot combine the changes. The user must resolve it. A merge joins two sets of changes. Locking stops others from updating a file until it is unlocked. Delta compression keeps only the differences between versions, which saves space. A revert returns to an earlier version, for reasons such as fixing errors, undoing scope creep, or regression testing. A version is any change in form. The trunk is the main line of development that is not a branch, and the working copy is a local copy of files from a repository, which works like a sandbox. Other terms include interleaved deltas, pull, push, share, and stream.

Quiz time!

5 questions about Version control

Question 1 of 5

What is version control mainly used for?

Keep exploring

This article is a child-friendly adaptation of the Wikipedia article on Version control, available under CC BY-SA 4.0.

Images from Wikimedia Commons. Tap any image to view credits and license.