`
songkang666
  • 浏览: 103117 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Git step by step 13 之Git对象

    博客分类:
  • GIT
 
阅读更多
        Git中有几种对象,像commit、tree、blob、tag,所有这些对象都存放于工作目录中.git/objects/下的各个文件夹中。

举个例子:
        当创建一个文件 touch file,然后进行git add file时,上面所说的目录中就会生成一个文件夹(两个英文字符命名的,这里假设是ac),那么在ac目录下会有一个一串(38个)字符命名的文件(假设是8516aa0d9ea6b86d3830f2e179864992f527ad),而ac与8516aa0d9ea6b86d3830f2e179864992f527ad合起来(即:ac8516aa0d9ea6b86d3830f2e179864992f527ad)就是我们刚git add之后,所创建的一个blob对象名,该对象名是一个SHA-1值(40个字符组成,前两个用作目录名,后38个用于文字名),而该blob对象中所存的内容即为file文件的内容。
所以一个文件对应一个blob对象。

        而tree对象对应的是目录,其内容是目录中的子目录或文件的名称。
举个例子:
        假设工作目录(根目录)里有dir/一个目录,和一个file文件,而dir/目录下又有file1和file2两个文件。那么进行 git add(add all)之后,生成的是三个blob对象(我试了下,当文件中没有内容时,不会生成blob对象,这就是说Git是针对文件中的内容进行SHA-1哈希的),对应这三个文件。此外,还会生成两个 tree 对象,对应工作目录的根目录以及dir/目录。

        commit对象是在每次git commit时所生成的,而tag对象是在建立里程碑时所生成的。

Ps:在.git/objects中的所有对象,在不手工(进入该目录,rm -r XXX)进行删除时,这些对象都会一直存在着,这也是为什么在git reset之后,还可以还原的,不过,从那么多对象文件中找出想要还原的commit,犹如大海捞针。但是总是有方法找到的,或许git reflog可以帮助走得更进一步。

        理解Git中的对象,能更好的理解分支、HEAD、master等。


        前面讲过,用git cat-file -p HEAD:file可以查看HEAD所指向的提交中file的内容,其实,这只是一个小的应用。
        所有对象都可以用git cat-file来查看,其中 git cat-file -t <object> 是查看该对象的类型 ,git cat-file -p <object> 是查看该对象的内容, git cat-file -s <object> 是查看该对象的大小。

举个例子:
$ git cat-file -p 6bb994 //(这个是一个commit对象的名字的前5位,不必打出全名,可区别于其他即可)
tree 8fc7e4efa8c47c058272663dc3cafcad52229b9d
parent c2456fcf8fcb8715704d4d4e4e8342c83e344b3e
author kevin <songkang666@126.com> 1366773192 +0800
committer kevin <songkang666@126.com> 1366773192 +0800

        可以看出,该commit对象中记录了它所对应的tree对象,前一次提交生成的commit对象(即它的父提交),提交人信息、对该 commit的描述。

        最后补充一条很重要的,Git在处理提交时,会把每次提交的文件全部内容(snapshot)都记录下来。
        举个例子:file在修改之后,再进行提交时,会新建一个完整地对应于它的blob对象,而不是覆盖掉之前提交时所产生的,也不是只对修改的部分(例如:添加了某些行)建立blob对象。

more:
GIT对象模型(推荐)
《Pro Git》
分享到:
评论

相关推荐

    Git Learn Version Control with Git A step-by-step Ultimate beginners Guide epub

    Git Learn Version Control with Git A step-by-step Ultimate beginners Guide 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    Git Learn Version Control with Git A step-by-step Ultimate beginners 无水印pdf

    Git Learn Version Control with Git A step-by-step Ultimate beginners Guide 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn...

    Learn Version Control With Git A step-by-step course for the complete beginner

    Learn Version Control With Git A step-by-step course for the complete beginner(中文)。亚马逊接近满分书籍,中文版。图文并茂。学习Git的好资料。 从官网一页一页的复制过来的,花了不少时间。

    Git Learn Version Control with Git A step-by-step Ultimate beginners Guide azw3

    Git Learn Version Control with Git A step-by-step Ultimate beginners Guide 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    Learn Version Control with Git: A step-by-step course for the complete

    "Learn Version Control with Git" is a beginner-friendly step-by-step course. The book doesn't require a deep technical background. Instead, it's aimed at beginners of version control and/or ...

    Git GUI.pptx

    git图形化界面操作说明,从创建本地仓库到更新远程仓库,step by step 简单直观。zsbd

    Git.Mastering.Version.Control.pdf

    Its step-by-step approach with useful information makes this course the ultimate guide to understanding and mastering Git. This course will show the road to mastery example by example, while also ...

    Git-2.21.0-64-bit.zip

    * The "git log" command by default behaves as if the --mailmap option was given. UI, Workflows & Features * The "git fast-export/import" pair has been taught to handle commits with log messages...

    Jenkins离线安装svn git maven插件包

    13.javadoc.hpi 14.workflow-api.hpi 15.script-security.hpi 16.junit.hpi 17.maven-plugin.hpi 18.git-client.hpi 19.matrix-project.hpi 2.workflow-step-api.hpi 20.git.hpi 3.credentials.hpi 4.scm...

    Git Essencial 第二版 最新2017.11月

    This step-by-step guide is packed with examples to help you learn and work with Git’s internals Who This Book Is For If you are a software developer with little or no experience of versioning systems...

    ssh框架整合step by step (springMVC + spring 5.0.4 + hibernate 5.0.12)

    ssh框架搭建step by step (springMVC + spring 5.0.4 + hibernate 5.0.12) 好久不弄web了, 周末心血来潮, 使用较新spirng/hibernate搭建一个ssh框架, 供有需要的同学参考/学习/使用. 使用eclipse开发, 搭建,分三步: ...

    git-second-step

    幻灯片-git2内部学习会议,“git next step”材料PDF制作方法安装 make 和 TexLive2013 编译make all

    intergitive:git的交互式教程

    intergitive -- Learn git by using ... It guides a user how to operate the GUI step-by-step and verifies the results immediately. Such an interactive mechanism aims to make learning git interesting. For

    深入理解学习Git工作流(git-workflow-tutorial)

    行文中实践原则和操作示例并重,对于Git的资深玩家可以梳理思考提升,而新接触的同学,也可以跟着step-by-step操作来操练学习并在实际工作中上手使用。关于Git工作流主题,网上体系的中文资料不多,主要是零散的操作...

    zmap-1.0.2

    zmap更新后不会安装了,git不行,yum不行。 找到了老版zmap-1.0.2,自己编译o~了 Debian/Ubuntu 系列 Step1: sudo apt-get install libgmp3-dev libpcap-dev gengetopt Step2: git clone git://github....

    oo-basic-step-by-step-example-java:Java面向对象练习

    Java面向对象编程练习描述根据测试目录下各包下README.md中的需求编写代码,使得测试代码可以运行通过。环境要求Java 8Intellij-IDEA如何开始在命令行中使用以下命令在用户本地任意目录下clone此题目库git clone ...

    微信小程序-微信小程序,还原游戏2048,目前实现部分功能

    git clone https://github.com/ShanaMaid/wx-2048.git Step 3 添加项目并运行 功能实现 [x] 基本游戏功能 [ ] 积分块移动动画 [x] 最高分数本地存储 [ ] 算法优化 版本更新记录 v1.0.1 最高分数本地存储 v...

    raco-macro-step

    例子 $ raco macro-step main.rkt安装从软件包服务器: $ raco pkg install raco-macro-step或者,从来源: $ git clone git://github.com/samth/raco-macro-step.git$ cd raco-macro-step$ raco pkg install执照...

    react-step-by-step

    React逐步教程请使用git checkout tags/step-[n]移动第1步:最少的设置以开始使用react; 步骤2:基本jsx语法; 第三步:嵌套渲染; 步骤4:零件的道具和造型; 步骤5:无状态和有状态组件; 步骤6:生命周期方法; ...

    gitbase web客户端;源代码{d} CE附带了一个新的UI,请在https://docs.sourced查看。科技/社区版/ - src-d / gitbase-web

    it allows to perform SQL queries on the Git history and the of the code itself.UsageWith Docker ComposeThe easiest way to run Gitbase Web and its dependencies is using .The first step is to populate a...

Global site tag (gtag.js) - Google Analytics