Safekipedia

Version control

Adventurer · ages 7–10Adapted 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 means keeping track of 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 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 an earlier 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

When teams build software, they often use several versions of the same program at once. Different developers may also work on different versions at the same time. Bugs or new features are often found in only some versions, because fixing one problem can cause another. To find and fix bugs, people need 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 version has bugs fixed but no new features (branch). The other version has new features added (trunk).

The simplest way to manage this is to keep many copies of the program and label them. Many large software projects have done this. It can work, but it is slow, because many almost identical copies must be kept, and mistakes happen easily. To solve these problems, people developed systems that do some or all of this work automatically. These systems are called revision control. They hide most of the steps from ordinary users. Revision control can also track changes to configuration files on Unix systems. Each version of a file gets a number and is linked to a timestamp and to the person who made the change. Versions can be compared, restored, and sometimes combined.

History

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

Early tools for managing computer programs appeared in the 1960s. IBM's OS/360 IEBUPDTE software update tool dates back to 1962 and may be an early ancestor of version control tools. Two other tools, The Librarian and Panvalet, were widely used on IBM computers.

In 1972, a full system for controlling source code, the Source Code Control System (SCCS), was started, also for OS/360. Its user manual, published in 1975, suggested that it was the first planned revision control system. The Revision Control System (RCS) followed in 1982. Later, Concurrent Versions System (CVS) added features that let teams work together over a network. After CVS, Subversion became the leading successor. Then distributed version control tools such as Git became popular.

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 together. This is harder for small changes but makes big changes easier. When data is checked out and changed, the change is usually not 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, and these branches later need to be merged. 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 an easier picture to understand. A merge happens when a new version combines changes from more than one earlier version. This can be hard when the changes overlap.

Specialized strategies

Engineering revision control began with formal ways of tracking changes to early blueprints or bluelines. This let people go back to an earlier version of a design when they got stuck. A revision table kept track of the changes, and revision clouds marked the edited parts of a drawing.

Version control is also used in business and law. "Contract redline" and "legal blackline" are some of the earliest forms of revision control and are still used today. The most advanced methods now track changes to CAD files on computers, replacing older hand-made methods. See product data management for more. Game studios often work with large files and teams from many different fields. They use version control systems that can handle big files, lock a file while someone is editing it, and update quickly. Common tools include Perforce and newer cloud-based systems.

Source-management models

Main article: Atomic commit

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

Main article: Merge (version control)

The simplest way to prevent problems with concurrent access is to lock files. This means only one developer at a time can change the central repository copy. Locking can help avoid 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. Merging image files may not produce an image at all. Labels, tags, and baselines all mark a snapshot of a project. "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) work differently from client–server systems. There is no single central place where everyone keeps their files. Instead, each person has a full working copy of the project, and each copy is a complete bona-fide repository. People share changes by sending patches to each other. Because of this, there is no main copy of the project by default. There are only working copies.

Everyday tasks, like saving changes, looking at history, and undoing changes, are quick. They do not need to connect to a central server. People only need to connect when they send or receive changes from others. Each working copy also acts like a backup of the project and its history, so information is less likely to be lost.

Best practices

Following good habits helps you get the most out of version control. The best habits can change depending on the tool and the field where it is used. In software development, common good habits include making small changes and making commits that cover only one task or fix. Commits should contain only code that works and does not knowingly break existing features. Other helpful habits are using branches to finish new features before release, writing clear commit messages that explain what was changed, why, and how, and using the same branching plan every time.

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

Costs and benefits

Version control has costs and benefits. These depend on the tool used 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, and it takes time and effort. People need to learn the ideas behind it and how to use the software. They also need to build good habits into how their team already works. Managers may need to help everyone keep these habits so the team gets real benefit.

The main benefit is keeping a history of changes. A developer can easily undo changes and try new ideas without fear of breaking existing code. Branching can help with deployment and release management. It also 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. 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. Clear notes and labels also help them communicate.

Integration

Some tools for tracking changes have many extra features. These help them work well with other tools and with the ways software is made.

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). Some experimental research tools can write commit messages on their own.

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)

Words can mean different things in different systems. A baseline is an approved version of a file that later changes can be made to. You can read more in 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 your changes from your working copy back to the repository. It also includes 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. 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 goes back to an earlier version. People might do this to fix errors, to undo scope creep, or for regression testing. A version is any change in form. The trunk is the main line of development that is not a branch. The working copy is a local copy of files from a repository, and it works like a sandbox. Other terms include interleaved deltas, pull, push, share, and stream.

Quiz time!

4 questions about Version control

Question 1 of 4

What is version control mainly about?

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.