Pro Git - Chapter 1

Pro Git

 

1. Getting Started

Local Version Control Systems

 

Centralized Version Control Systems

 

Distributed Version Control Systems

 Git Basics

Snapshots, Not Differences

 Most other systems (CVS, Subversion, Perforce, Bazaar, and so on) think of the information they keep as a set of files and the changes made to each file over time,

 

 Instead, Git thinks of its data more like a set of snapshots of a mini filesystem. Every time you commit, or save the state of your project in Git, it basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. 

 

Nearly Every Operation Is Local

 Most operations in Git only need local files and resources to operate — generally no information is needed from another computer on your network. Because you have the entire history of the project right there on your local disk, most operations seem almost instantaneous.

Git Has Integrity

 Everything in Git is check-summed before it is stored and is then referred to by that checksum. The mechanism that Git uses for this checksumming is called a SHA-1 hash. The checksum is calculated based on the contents of a file or directory structure in Git.

The Three States

  Git has three main states that your files can reside in: committed, modified, and staged. 

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.

This leads us to the three main sections of a Git project: the Git directory, the working directory, and the staging area.

The Git directory is 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 directory 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 simple file, generally contained in your Git directory, that stores information about what will go into your next commit. It’s sometimes referred to as the index, but it’s becoming standard to refer to it as the staging area.

The basic Git workflow goes something like this:
  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.

Installing Git

Installing on Linux

If you’re on Fedora, you can use yum:
$ yum install git-core
 
Or if you’re on a Debian-based distribution like Ubuntu, try apt-get:
$ apt-get install git-core

Installing on Mac

The easiest is to use the graphical Git installer, which you can download from the Google Code page : http://code.google.com/p/git-osx-installer

First-Time Git Setup

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.

Your Identity

$ git config --global user.name "Jerry Lee"
$ git config --global user.email jerry.lee@example.com
 

Your Editor

You can configure the default text editor that will be used when Git needs you to type in a message.  
If you want to use a different text editor, such as Emacs, you can do the following: 
$ git config --global core.editor emacs

Your Diff Tool

You can configure the default diff tool to use to resolve merge conflicts.
Say you want to use vimdiff:
$ git config --global merge.tool vimdiff

Checking Your Settings

$ git config --list
 
You can also check what Git thinks a specific key’s value is by typing git config {key}:
$ git config user.name

Getting Help

$ git help 
$ git  --help
$ man git-




留言

熱門文章