Git 基本原理

Git Server

> useradd git ;加 git 用户
> git init --bare --shared []

在指定 directory 目录下创建 git 库。通常 directory 为 .git 形式,比如 www.git 一类的。详细 OPTIONS 请了解 git init -h。

文件

/etc/ssh/ssh_config ;system-wide file
~/.ssh/config ;user-specific file. 注意 .ssh 目录及其文件的读写权限。
~/.ssh/authorized_keys
/etc/passwd ;git 用户的 shell:/bin/bash -> /usr/bin/git-shell。

存储原理

Git 基本原理_第1张图片
snapshots(存储快照)

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.

Git 基本原理_第2张图片
areas-The Three States
  • difference between head/working tree/index in git
  • NDP Software git-cheatsheet (Andrew Peterson)
    每个命令对各类数据存储区的影响做了说明,值得参考。
    数据存储区:stash,workspace,index,local repository,upstream repository(remote repository)。
    Git 基本原理_第3张图片
    Index(staging area, cache)

index:Files you want to commit. Before you “commit” (checkin) files, you need to first add them to the index. Also called "current directory cache", "staging area", "cache" or "staged files".

命令对存储的影响
  • git checkout
    从 Repository 签出到 Working Directory;
  • git reset
    将 Repository 恢复到 ,同时恢复 Working Directory;
  • git rm, git mv -> Working Directory
  • git add -> Staging Area
    The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. However, git add doesn't really affect the repository in any significant way - changes are not actually recorded until you run git commit.
    In conjunction with these commands, you'll also need git status to view the state of the working directory and the staging area.
  • git commit -> .git directory (Repository)
  • git push -> Remote Repository

分支原理

How does Git know what branch you’re currently on? It keeps a special pointer called HEAD. In Git, this is a pointer to the local branch you’re currently on.

这三张图足以说明一切。

Git 基本原理_第4张图片
A commit and its tree(数据结构).png
Git 基本原理_第5张图片
commits-and-parents.png
Git 基本原理_第6张图片
Divergent history.png

你可能感兴趣的:(Git 基本原理)