It is a system that records changes done to a file or set of files over a time period so that you can recall specific versions later whenever needed.
Following are the benefits of Version Control System:
● It allows you to revert selected files back to a previous state in case of any issue.
● It allows to revert the entire project back to a previous state if there are some serious issues.
● Allows to compare changes over time.
● Allows to check who last modified something that might be causing a problem.
● One of the key benefit is that we can easily identify who introduced an issue and when.
These are the centralized systems that have single server that contains all the versioned files, and a number of clients that check out files from that central place. For many years these centralized systems are being used by the developers all across the world. Example Subversion, Perforce etc.
Following are the benefits of Centralized Version Control System:
● Administrators have fine-grained control over who can do what.
● It is easy to maintain the code in central place.
● Its easy to administer the central code repository.
In a DVCS (such as Git, Mercurial, Bazaar or Darcs), clients don't just check out the latest snapshot of the files; rather, they fully mirror the repository, including its full history. Thus, if any server dies, and these systems were collaborating via that server, any of the client repositories can be copied back up to the server to restore it. Every clone is really a full backup of all the data.
Git thinks of its data more like a series of snapshots of a miniature file system. With Git, every time you commit, or save the state of your project, Git basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. To be efficient, if files have not changed, Git doesn't store the file again, just a link to the previous identical file it has already stored. Git thinks about its data more like a stream of snapshots.
Everything in Git is check-summed before it is stored and is then referred to by that checksum. This means it's impossible to change the contents of any file or directory without Git knowing about it. This functionality is built into Git at the lowest levels and is integral to its philosophy. You can't lose information in transit or get file corruption without Git being able to detect it.
The mechanism that Git uses for this checksumming is called a SHA-1 hash. This is a 40-character string composed of hexadecimal characters (0-9 and a-f) and calculated based on the contents of a file or directory structure in Git.
Git stores everything in its database not by file name but by the hash value of its contents.
Git has three main states that your files can reside in:
● Committed means that the data is safely stored in your local database.
● Modified means that you have changed the file but have not committed it to your database yet.
● Staged means that you have marked a modified file in its current version to go into your next commit snapshot.
Following are the three main sections of Git project:
● Git directory
● Working tree
● Staging area
It is the place where Git stores the metadata and object database for your project.
This is the most important part of Git, and it is what is copied when you clone a repository from another computer.
The working tree is a single checkout of one version of the project. These files are pulled out of the compressed database in the Git directory and placed on disk for you to use or modify.
The staging area is a file, generally contained in your Git directory, that stores information about what will go into your next commit.
It is nothing but the staging area which stores information about what will go into your next commit.
The basic Git workflow goes something like this:
1 You modify files in your working tree.
2 You selectively stage just those changes you want to be part of your next commit, which adds only those changes to the staging area.
3 You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.
Here is the syntax of the command to install Git in Linux:
$ sudo dnf install git-all
Here is the syntax of the command to install Git in Ubuntu:
$ sudo apt install git-all
Here is the syntax of the command to install Git on Mac:
$ git --version
It is a tool that lets you get and set configuration variables that control all aspects of how Git looks and operates.
Here is the syntax of the command to initialize the Git repository:
$ git init