参考:https://git-scm.com/book/zh/v2 第十章
目录
1 2 3
| > ls .git/ FETCH_HEAD config hooks info objects refs HEAD description index logs packed-refs
|
- FETCH_HEAD
- config 文件包含项目特有的配置选项
- hooks 目录包含客户端或服务端的钩子脚本(hook scripts)
- info 目录包含一个全局性排除(global exclude)文件,以放置那些不希望被记录在 .gitignore 文件中的忽略模式(ignored patterns)
- objects 目录存储所有数据内容
- refs 目录存储指向数据(分支、远程仓库和标签等)的提交对象的指针
- HEAD 文件指向目前被检出的分支
- description 文件仅供 GitWeb 程序使用
- index 文件保存暂存区信息
- logs
- packed-refs 打包标头和标签以便高效的存储库访问
Git 对象
存数据
1 2
| > echo 'test content' | git hash-object -w --stdin d670460b4b4aece5915caf5c68d12f560a9fe3e4
|
git hash-object 会接受你传给它的东西,而它只会返回可以存储在 Git 仓库中的唯一键
-w 选项会指示该命令不要只返回键,还要将该对象写入数据库中
–stdin 选项则指示该命令从标准输入读取内容;若不指定此选项,则须在命令尾部给出待存储文件的路径
读数据
1 2
| > git cat-file -p d670460b4b4aece5915caf5c68d12f560a9fe3e4 test content
|
cat-file 命令从 Git 那里取回数据
-p 选项可指示该命令自动判断内容的类型,并为我们显示大致的内容
树
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| > git cat-file -p mydevelop^{tree} 100644 blob 0df7064d66e779373977228905e967f4702c971a .gitignore 040000 tree af762ffe20cb89c68a7ae72e3f7a99e43ab58057 .idea 100644 blob b786da0f54d4d717b17bc98a04455896df4a6848 README.md 100644 blob 9daeafb9864cf43055ae93beb0afd6c7d144bfa4 a.txt 040000 tree eb8d2cab3a4b6fc3be41f51c2d981bdd6c6b6811 app 100644 blob e062745212f7405138c213640bece166f780fb08 build.gradle 040000 tree 534ca71be4da3c5a632da7f9e197c2158c28e2b5 card 100644 blob 82618cecb4d1cf137df18eca8dbe88e1b3b2c2b8 gradle.properties 040000 tree b2023d378ce7e54a39caa88bb75df44b5ce24620 gradle 100755 blob cccdd3d517fc5249beaefa600691cf150f2fa3e6 gradlew 100644 blob e95643d6a2ca62258464e83c72f5156dc941c609 gradlew.bat 040000 tree 042951a99a230dfe394213ea1031487217355c00 poseidon 100644 blob 06c1349fc4b6bdc685de025e6a2de51ae14dfc1e settings.gradle
|
加入暂存区
1 2
| git update-index --add --cacheinfo 100644 \ f7c6dd0164fe0eb4fde767f9e731a6c8ade0b69f b.txt
|
–add 选项 加入一个新的暂存区
–cacheinfo 选项,因为将要添加的文件位于 Git 数据库中,而不是位于当前目录下
100644 表明这是一个普通文件。 其他选择包括:100755,表示一个可执行文件;120000,表示一个符号链接
写入tree
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| > git write-tree 6939cd1c819ddc253aaac450638cd89366271cea > git cat-file -p 6939cd1c819ddc253aaac450638cd89366271cea 100644 blob 0df7064d66e779373977228905e967f4702c971a .gitignore 040000 tree af762ffe20cb89c68a7ae72e3f7a99e43ab58057 .idea 100644 blob b786da0f54d4d717b17bc98a04455896df4a6848 README.md 100644 blob 9daeafb9864cf43055ae93beb0afd6c7d144bfa4 a.txt 040000 tree eb8d2cab3a4b6fc3be41f51c2d981bdd6c6b6811 app 100644 blob f7c6dd0164fe0eb4fde767f9e731a6c8ade0b69f b.txt 100644 blob e062745212f7405138c213640bece166f780fb08 build.gradle 040000 tree 534ca71be4da3c5a632da7f9e197c2158c28e2b5 card 100644 blob 82618cecb4d1cf137df18eca8dbe88e1b3b2c2b8 gradle.properties 040000 tree b2023d378ce7e54a39caa88bb75df44b5ce24620 gradle 100755 blob cccdd3d517fc5249beaefa600691cf150f2fa3e6 gradlew 100644 blob e95643d6a2ca62258464e83c72f5156dc941c609 gradlew.bat 040000 tree 042951a99a230dfe394213ea1031487217355c00 poseidon 100644 blob 06c1349fc4b6bdc685de025e6a2de51ae14dfc1e settings.gradle
|
提交tree
1 2 3 4 5 6 7 8 9 10 11
| > echo 'b.txt write' | git commit-tree 6939cd1c819ddc253aaac450638cd89366271cea a6120d04b63cd599bbbd62eb789dbd290b275bc2
> git cat-file -p a6120d04b63cd599bbbd62eb789dbd290b275bc2 tree 6939cd1c819ddc253aaac450638cd89366271cea author 小豹 <xiaobao.spf@alibaba-inc.com> 1621826585 +0800 committer 小豹 <xiaobao.spf@alibaba-inc.com> 1621826585 +0800
b.txt write
|
包文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| > ls .git/objects 4d 69 81 84 9d a0 a6 b6 d6 e2 f7 fa info pack
> git gc Enumerating objects: 475, done. Counting objects: 100% (475/475), done. Delta compression using up to 12 threads Compressing objects: 100% (215/215), done. Writing objects: 100% (475/475), done. Total 475 (delta 180), reused 466 (delta 175), pack-reused 0
> ls .git/objects 69 a6 d6 e2 f7 info pack
|
引用规范
https://yuque.antfin.com/xiaobao.spf/ad2gcp/eu9nh0
传输协议
环境变量