Skip to content

What is Version Control?

Aditi edited this page Sep 1, 2016 · 4 revisions

Writing code is a messy affair. There's a lot of trial-and-error. Sometimes introducing a new line of code can completely break your application!

Though the traditional ctrl+z-ing is still a thing...you really can't do it if you have multiple files and/or don't know how much to remove to bring your code back to it's last working state.

This is where a Version Control System (VCS) comes into play. A VCS manages versions of your code so that you can go back and forth between these versions and if a version of your code is buggy/incomplete and breaks your application, you can just go back to a previous version of the application to bring it back to a working state.

Wait....what? Can you elaborate?

Ok. So imagine you've written some code. Let's name the current state of your code version 1. Now you go ahead and add some more lines of code to this version. Let's call this state version 2. You run your code and your code runs flawlessly. Happy days!

But now you want to add some more code to add some new functionality to your code. This brings your code to a new state. Let's call this version 3. You run the code and...it doesn't run. It breaks. You sad. =(

Now, if it were just one line in one single file that you'd added, you could fall back to using your trusty old Ctrl + Z to fix this. But imagine a large or medium size project where you'd have to go into all the files and see what needs to be undone to bring your code from state version 3 to the perfectly working state version 2. Such hassle! Much irritation.

Now with a Version Control System, things are a little bit easier. A VCS keeps track of these version changes in the form of snapshots of your code. In the above example, when we know that Version 3 of the code isn't working, we can just immediately jump back to the previous version! And what's more, you can see exactly what files and lines changed between those versions which gives you a great insight into what to fix.

Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.

Types of VCS

Version Control Systems come in two forms

  • Centralized VCS (CVSC)
  • Distributed VCS (DVCS)

Centralized VCS

Centralized version control systems are based on the idea that there is a single "central" copy of your project somewhere (probably on a server), and contributors (programmers like yourself) will add their changes to this central copy.

Adding (also known as committing in CVCS) a change simply means recording the change in the central system. Other programmers can then see this change. They can also pull down (download aka taking an update) the change, and the version control tool will automatically update the contents of any files that were changed and make it consistent with the central system.

Subversion is a popular CVCS.

Distributed VCS

Distributed VCSs do not necessarily rely on a central server to store all the versions of a project's files. Instead, every developer downloads (also known as clones) a copy of a repository and has the full history of the project on their own hard drive. This copy (or "clone") has all of the metadata of the original.

The developer can then proceed to modify the files on his/her own system, and when the time comes to share this code, it can committed and pushed back into the central server.

Distributed VCS has caught traction over the last decade as it allows developers to

  • work on things locally
  • not rely on internet to connect to a central server

Git ❤️ & Mercurial are popular DVCS.