网站黑白了,国外网站做freelancer,做网站窗体属性栏设置文字居中,软件开发者英文Git 原理#xff08;提交对象#xff09;
这一块主要讲述下 Git 的原理。
在进行提交操作时#xff0c;Git 会保存一个提交对象#xff08;commit object#xff09;#xff1a;
该提交对象会包含一个指向暂存内容快照的指针#xff1b;
该提交对象还包含了作者的姓…Git 原理提交对象
这一块主要讲述下 Git 的原理。
在进行提交操作时Git 会保存一个提交对象commit object
该提交对象会包含一个指向暂存内容快照的指针
该提交对象还包含了作者的姓名和邮箱、提交时输入的信息以及指向它的父对象的指针
首次提交产生的提交对象没有父对象普通提交操作产生的提交对象有一个父对象而由多个分支合并产生的提交对象有多个父对象 接下来通过实践的方式来探索 Git 提交 的原理。 我们可以自己手动创建个文件夹然后里面创建个 index.html并通过 git init 进行初始化。 接下来进入目录下的隐藏文件夹 .git所有需要存储的东西都会存储在 git 下的 objects 中
nathanchen192 tests2 % ls
index.html
nathanchen192 tests2 % cd .git
nathanchen192 .git % ls
HEAD config description hooks info objects refs首先我们修改一波 index.html 文件然后进行git add .这样会把所有文件放入到暂缓区中再次查看对应文件会发现多了 69 文件夹里面存放二进制文件。
nathanchen192 objects % ls
69 info pack接下来查看文件的种类和对应内容命令如下所示
git cat-file -t file # 查看文件的种类
git cat-file -p file # 查看文件的内容nathanchenNathansMacBook-Pro 05 % pwd
/test3/.git/objects/69
nathanchen192 69 % ls
763a710c37f7ec0e610fb4ae1cbde7e8e7524d
nathanchen192 69 % git cat-file -t 6976
blob
nathanchen192 69 % git cat-file -p 6976
!DOCTYPE html
html langen
headmeta charsetUTF-8meta nameviewport contentwidthdevice-width, initial-scale1.0titleDocument/title
/head
body/body
/html%注这里的 69 指的是 69 文件夹而 76 指的69文件夹下的 76 开头的文件。
然后我们进行一波提交并在对应文件夹下查看发现新增了 0a 和 8d 两份文件
nathanchenNathansMacBook-Pro test3 % git commit -m 1 commit
[master (root-commit) 8d8182a] 1 commit1 file changed, 11 insertions()create mode 100644 index.htmlnathanchen192 objects % ls
0a 69 8d info pack查看 0a 和 8d 两个文件夹及其对应文件发现 0a 是包含文件依赖关系的对象8d 为 Commit 对象
nathanchen192 0a % git cat-file -t 0a68
treenathanchen192 0a % git cat-file -p 0a68
100644 blob 69763a710c37f7ec0e610fb4ae1cbde7e8e7524d index.htmlnathanchen192 8d % git cat-file -t 8d81
commitnathanchen192 objects % git cat-file -p 8d81
tree 0a683a4b7535845bb37e7444ab95404933d547e5
author Captain Drake 9393079captain_drakeuser.noreply.gitee.com 1726479021 0800
committer Captain Drake 9393079captain_drakeuser.noreply.gitee.com 1726479021 08001 commit这时候我们再次通过 log 来进行查看提交历史会发现 8d81… 正好对应 objects 下新增的文件 nathanchenNathansMacBook-Pro test3 % git log
commit 8d8182a27fe263a6c20a8136c1dbc7768f988e02 (HEAD - master)
Author: Captain Drake 9393079captain_drakeuser.noreply.gitee.com
Date: Mon Sep 16 17:30:21 2024 08001 commit
(END)总结
1-关于 git add 和 git commit 的底层操作
git add会将对应文件转化为二进制文件保存在 objects 里面。
git commit 会输出一个 Commit 对象里面包含属性tree它会指向另一个对象这个对象包含本次提交中关联对象的映射关系从而找到在暂存区中的二进制文件。 结合以上案例进行理解 2-关于每次 Commit 形成的链条
每次 Commit 都会输出 Commit对象里面包含 tree 的相关信息。除了第一次的 Commit对象之后的 Commit 对象都会包含 parent 属性从而指向前一次 Commit最终形成提交的历史记录。