CSC/ECE 517 Fall 2013/ch1w6 zs

From Expertiza_Wiki
Jump to navigation Jump to search

CSC/ECE 517 Fall 2013/ch1w6 zs

Synopsis of Git book

Introduction

Git is by far the best Version Control System on the market and it's free.

Version Control System

Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control. A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version. It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.

Generally, there are three kinds of version control system, which are local, centralized and distributed VCSs. Figures are illustrated below. Local Version Control

Centralized Version Control System

Distributed Version Control System

History

Git was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.

When things between the community that developed linux kernel and the commercial company that developed Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.

For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .

What is Git

Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.

Git's Snapshots way of thinking data

This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.

Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.

Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.

Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.

Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.

The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied. The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate. The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.

Generally, the follow three steps are how Git works:

1.You modify files in your working directory.

2.You stage the files, adding snapshots of them to your 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.

Getting Started on Git

Installing Git

First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)

Install from Source

One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies.

$ yum install curl-devel expat-devel gettext-devel \
 openssl-devel zlib-devel
$ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \
 libz-dev libssl-dev

Once this is done, you can go ahead and download the latest version of Git

 http://git-scm.com/download

And then, compile and install

$ tar -zxf git-1.7.2.2.tar.gz
$ cd git-1.7.2.2
$ make prefix=/usr/local all
$ sudo make prefix=/usr/local install

After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.

$ git clone git://git.kernel.org/pub/scm/git/git.git

Install on Linux

It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum

$ yum install git-core

If you are on a Debian-based distribution like Ubuntu, use apt-get

$ apt-get install git

Install on Windows

Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it.

http://msysgit.github.com/

After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.

First time set-up

You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.

A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.

Git comes with a tool called git config that lets you get and set configuration variables that control all aspects of how Git looks and operates. These variables can be stored in three different places:

/etc/gitconfig file: Contains values for every user on the system and all their repositories. If you pass the option--system to git config, it reads and writes from this file specifically. ~/.gitconfig file: Specific to your user. You can make Git read and write to this file specifically by passing the --global option. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.