Automated Version Control

Overview

Teaching: 15 min
Exercises: 0 min
Questions
  • What is version control and why should I use it?

Objectives
  • Understand the benefits of an automated version control system.

  • Understand the basics of how automated version control systems work.

Version control can keep track of the changes submitted by each collaborator, and when those changes were submitted. Even if you aren’t collaborating with other people, automated version control is much better than this situation:

"Piled Higher and Deeper" by Jorge Cham, http://www.phdcomics.com

“Piled Higher and Deeper” by Jorge Cham, http://www.phdcomics.com

This is a common problem: multiple nearly-identical versions of the same document. Popular word processors have features to help with revisions:

Version control software Git (which we will be using in today’s workshop) enables you to create an initial version of a project (an initial commit)), and then commit changes incrementally as you modify the files in your project. This is not automatic, but something you do intentionally to mark your progress. Git tracks the state of all files in your project (called a repository) at each commit, and you can view any previous commits whenever you want to see a snapshot of your project at that time (this is called checking out a commit).

Changes Are Saved Sequentially

Changes tracked by a Git respository are separate from the project files. Unlike a Microsoft Word document, the file itself does not know its own history. The Git respository history is stored inside a directory called .git in the folder for your repository. It’s best to simply ignore this directory and not make any changes to the files there.

Different Versions Can be Saved

Multiple users can make changes to the same file in your project, but this can cause merge conflicts if the same part of the file has been edited by multiple users. More on this later.

Multiple Versions Can be Merged

Git is a powerful tool for tracking changes and developing new features in coding projects. Multiple collaborators can create branches) to work on a single project simultaneously, and then merge the different versions together. This is a standard practice in modern software development. Repositories can be hosted centrally in places like GitHub so that collaborators can easily sync changes by pulling) down the latest commits to their local copy of the repository.

Imagine you drafted an excellent paragraph for a paper you are writing, but later you select the paragraph and delete it. How would you retrieve the excellent version of your conclusion? Is it even possible?

Recovering the excellent version is only possible if you created a copy of the file when that paragraph was still part of your document. Version control only tracks what you commit. If you commit small changes to your files, and commit often, you will have an extremely detailed history of your changes. The number of “snapshots” of your work are equal to the number of commits you make.

Key Points

  • Version control is like an unlimited ‘undo’.

  • Version control also allows many people to work in parallel.