Pages

Friday, February 22, 2019

Understanding Version Control System

Version Control System
Managing code is always hard. In the Early days when we used to write code, we usually save them to a disk location for future references. One developer working on a project knows where the code is saved, what changed and how it works. 

But what if the project is written by multiple people. Saving the code to a same location on the disk can be conflicting. One user makes the changes and other gets confused with them. Moving the code to production can be very confusing.

What is  
  • We made a change to the code, realised it was a mistake and wanted to revert back? 
  • We lost the code? 
  • What is we lost the code and we had a backup which is very old then new code? 
  • What if i need to maintain multiple versions of the same code for different projects? 
  • How can we prove that a particular change has broken the code or fixed the code? 
  • What is we need to submit a change to some others code? 
  • What if we want to see how much work is being done, and where and by whom? 
  • What if we need to experiment with the new feature without interfering with the working copy of the code? 
Source Code Management System is an answer for the above problems? 
Source Code Management System ( SCM ) or Version Control System ( VCS ) or Revision Control System ( RVCS ) is a system that records changes to a file or a set of files over time. 

VCS allows you to track the history of a collection of files by creating different version of the collection of file ( or files). Each version captures a snapshot of the files at a certain point of time. Vcs allows to switch between these versions. These versions are stored place  specific place called repository.

Vcs also allows us to revert files back to a previous state, revert a project back to its previous good state, compare changes over time, can show who made changes lastly, whose code introduced a bug etc. 

Lastly if we screw things up or loose files we can easily recover using Vcs

Now that we understood what Vcs is , we will see the types of Vcs , their advantages and disadvantages.
  
Local Version Control System - In this system, developers store multiple version of the files in separate directories and used them when needed. This is a pretty easy and simple to use with smaller projects but very error prone.
  
Most of the times , it is easy to forget which directory you are in and accidently write to a wrong file or copy over files that we don't mean to. In order to deal with this situation we came up with the Local Version Control System. 
Local version control diagramLvcs has a simple database that kept all the changed to files under revision control. A revision control system is capable of reverting a modification done to a file to its earlier state. It allows users to identify and correct errors and provide security to the data and information. 

Though this used to work well, the problem with this is that if developers want to collaborate with other developers the Lvcs are not suitable. Since we make all the code changes or code saving to a local version control system, other developers working on different systems can’t access this database. In order to solve this problem , people came up with the Centralized Version Control System ( Cvcs ). 

Centralized Version Control System - In order to solve multiple users accessing the Vcs , Cvcs was created. In this a Single independent server is maintained which will have all users versioned files, and multiple users or clients can connect to this machine to download the code or make changes to the code. The problem with this type of system is a single point of failure. If this single server containing all users code is crashed , then there is no way we can get back the code. Some of these type of tools include CVS, Subversion, perforce etc 
Centralized version control diagram 
In order to solve this single point of failure server, people came up with the Distributed Version Control System ( Dvcs ) 

Distributed Version Control System - In this type of system, there will be a single server where all the source code will be available. New users or existing users who want the code will download the code. In this case they don’t just download the code but mirror the full repository. If the machine where the source code exists crashes or dies , users don’t need to worry about the source code since every one will have the full mirror of the source code. Repositories mirrored on the client machine can be used to restore the repository on the server machine. 
Distributed version control diagram 

Finally what does the Version Control provides? 
Backup/Restore:  Files saved can be backed up or restored to a specific moment in time. Need a File to be changed to a version last year , we have that 
Synchronization: Lets people share files and stay up-to-date with the latest version 
Track Changes – As details about the files updated, merged, deleted will be available in the history maintained. 
Branching and merging. A larger sandbox. You can branch a copy of your code into a separate area and modify it in isolation (tracking changes separately). Later, you can merge your work back into the common area.

No comments :

Post a Comment