Git 基本原理

Git Server

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

在指定 directory 目录下创建 git 库。通常 directory 为 <name>.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。

存储原理

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.

areas-The Three States

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 <commit>
    将 Repository 恢复到 <commit>,同时恢复 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.

这三张图足以说明一切。

A commit and its tree(数据结构).png
commits-and-parents.png
Divergent history.png

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容