Introduction To Version Control System

Introduction To Version Control System

VCS(VERSION CONTROL SYSTEM) is used to

  • They retrieve the past versions of our file or directory and let's us see who changed what files. In simple words it can Undo the changes done to a piece of code and roll back to the previous versions of code. After doing proper testing of the new code,then we implement the new code.
  • This can be used as an medium for multiple people to collaborate on the same projects together.
  • VCS keeps historical copies of the code which in other words means that VCS helps us to keep track of the changes in our files. We can know who made the changes and when

DIFFING FILES

  • If there are two copies of the similar code and we want to check the difference between them then we can do this by diffing two files

    diff file1.x file2.x

  • If the output of the diff command shows a lesser than < symbol followed by a line of code then it means that a line was removed from the first file(file1.py).
  • Else, if it shows a greater than > symbol followed by a line of code then it means that the line was added to the second file(file2.x)
//TYPE THE FOLLOWING COMMANDS IN YOUR TERMINAL
touch file1.txt  //touch command is used to create a file in linux systems.
touch file2.txt 
//NOW ADD SOME CONTENT TO FILE1 AND COPY THAT TO FILE2
//MODIFY FILE2 WITH MINOR CHANGES.
cat file1.txt  //cat command is used to display the entire file.
cat file2.txt
diff file1.txt file2.txt //You can view the changes in both the files
  • Now if we want more information regarding the changes in our files, then we can add the -u flag to the diff command

    diff -u file1.x file2.x

    Note : You can explore various other commands such as

    1. wdiff - highlights the words that are changes in a file.
    2. meld - provides two- and three-way comparison of both files and directories, and has support for many popular version control systems.
    3. KDiff3 - a GUI diff tool that allows you to create a diff of two/three files and selectively choose which lines make up the merged file.
    4. vimdiff - starts Vim on two (or three) files. Each file gets its own window. The differences between the files are highlighted. This is a nice way to inspect changes and to move changes from one version to another version of the same file.

APPLYING CHANGES

  • We can send a diff with the changes to a piece of code so that someone can see the modifies code (How it looks like).

    diff -u file1.x file2.x > change.diff ( ">" is the redirection operator which redirects the output of diff command to the change.diff file )

The generated file is referred to as the diff file or the patch file. It includes all the changes between the old file and the new file plus the additional context needed to understand the changes and to apply those changes back to the original file.

Now if the person receiving the diff file wants to apply the changes to the original file then he can read the diff file and manually got through the file and apply the modifications. But, this is way too tidious for a person. So, he can make use of the patch command.

patch originalFile.x < change.diff

  • patch takes the file generated by the diff command and applies the changes to the original file.

In VCS, we can make edits to multiple files and treat that collection of edits as a single change which is commonly known as a commit.

Whenever you write a commit message after making a change, it's as if the current version of yourself is explaining your decisions to a future version of you or others in the future who might work on the same scripts ans configurations in the future.

In VCS, the author of a commit can record why the change was made and also the bugs & issues that were fixed by this change.

Files are usually organiseds in repositories which contains separate software projects or just group of all related code. A Repository can be thought as a folder that contains all the files that are related to a particular project.

repo.gif

  • If there are a lot of people in developing software, some developers may have access to only some of the repositories .
  • A single repository may have as little as one person using it or it can go upto thousands of contributors using the same repository.
  • VCS may be used to store configuration files, documentation, data files or any other content that we may need to track. VCS is useful to track text files which may be compared with diff and modified with patch.

Within a VCS, project files are organised in centralized locations called repositories where they can be called upon later.