git内部原理

  从根本上来讲 Git 是一个内容寻址(content-addressable)文件系统,并在此之上提供了一个版本控制系统的用户界面。Git 的核心部分是一个简单的键值对数据库(key-value data store)。 你可以向该数据库插入任意类型的内容,它会返回一个键值,通过该键值可以在任意时刻再次检索(retrieve)该内容。

.git目录

当在一个新目录或已有目录执行 git init 时,Git 会创建一个 .git 目录。 这个目录包含了几乎所有 Git 存储和操作的对象。 如若想备份或复制一个版本库,只需把这个目录拷贝至另一处即可。

.git目录结构

$ ls -F1
HEAD
config*
description
hooks/
info/
objects/
refs/
View Code

注:ls -F1,-F参数好理解。哪个-1初次见还是很奇怪的,-1的意思是一个文件单独显示一行。

该目录下可能还会包含其他文件(比如index文件),不过对于一个全新的 git init 版本库,这将是你看到的默认结构。

description 文件:仅供 GitWeb 程序使用,我们无需关心。

config 文件:包含项目特有的配置选项。

HEAD 文件:指示目前被检出的分支;

index 文件:保存暂存区信息。

objects 目录:存储所有数据内容

refs 目录:存储指向数据(分支)的提交对象的指针

info 目录:包含一个全局性排除(global exclude)文件,用以放置那些不希望被记录在 .gitignore 文件中的忽略模式(ignored patterns)

hooks 目录:包含客户端或服务端的钩子脚本(hook scripts)

Git objets

参考:https://www.youtube.com/watch?v=nDO6lilgpHM

  • Every obiect consists of three things:
  • type
  • size and
  • content
  • The size is simply the size of trOcontents, the contents depend on what type of object it is. There are object types:
  • A blob is used to store file data-it is generally a file.
  • A tree is basically like a directory-it references a bunch of other trees and/or blobs(i.e. files and sub-directories).
  • A commit points to a single tree, marking it as what the project looked like at a certain point in time. It contains meta-information about that point in time, such as a timestamp, the author of the changes since the last commit,a pointer to the previous commit(s), etc.
  • A tag is a way to mark a specific commit as special in some way. It is normally used to tag certain commits as specific releases or something along those lines.
  • Almost all of Git is built around manipulating this simple structure of four different object types. It is sort of its own little file-system that sits on top of your machine's file-system.

 

原文地址:https://www.cnblogs.com/kelamoyujuzhen/p/9954323.html