me

Git 对象原理


初始化 git

#四个文件
config  description  FETCH_HEAD  HEAD  
#四个文件夹
hooks  info  objects  refs
#展开的文件
├─hooks
├─info
     exclude
├─objects
  ├─info
  └─pack
└─refs
    ├─heads
    └─tags

工作区与暂存区

git commit

├─info
      exclude

├─objects
  ├─19
      0b00d560cb8ac4e17678e8fccc7a2af8057bdd

  ├─2a
      93d00994fbd8c484f38b0423b7c42e87a55d48

  ├─info
  └─pack
└─refs
    ├─heads
    └─tags
├─info
      exclude

├─logs
  HEAD

  └─refs
      └─heads
              master

├─objects
  ├─19
      0b00d560cb8ac4e17678e8fccc7a2af8057bdd

  ├─2a
      93d00994fbd8c484f38b0423b7c42e87a55d48

  ├─a0
      197cf5327fec251ae14d063fb50d6d3e570674

  ├─a3
      d91d125103f57b7b60d7ebd6502aa0987828ab

  ├─info
  └─pack
└─refs
    ├─heads
      master

    └─tags

查看 commit 对象内容和类型

git cat-file -t a3d91d12
# commit
git cat-file -p a3d91d12
# tree a0197cf5327fec251ae14d063fb50d6d3e570674
#                                                   时间戳      时区
# author Jack-Zhang-1314 <fwqaaq@gmail.com> 1656707371 +0800
# committer Jack-Zhang-1314 <fwqaaq@gmail.com> 1656707371 +0800
# 
# 1st commit

查看 tree 对象的内容和类型

git cat-file -t a0197c
#tree
git cat-file -p a0197c
# 100644 blob 2a93d00994fbd8c484f38b0423b7c42e87a55d48    hello.txt
# 100644 blob 190b00d560cb8ac4e17678e8fccc7a2af8057bdd    temp.txt

查看 commit 对象和指针HEAD

cat .\.git\refs\heads\master
# a3d91d125103f57b7b60d7ebd6502aa0987828ab
cat .git/HEAD
# ref: refs/heads/master
                          ----------> hello.txt
                          |
commit(tree中的内容) ---> tree(包含blob对象文件)
                          |
                          ----------> temp.txt

修改 commit


├─objects
  ├─19
      0b00d560cb8ac4e17678e8fccc7a2af8057bdd

  ├─2a
      93d00994fbd8c484f38b0423b7c42e87a55d48

  ├─65
      4580c8026cf5b0ab07c5572f353409e3c83792

  ├─80
      993781b54ed1b81e47a31e6427940c1a9deafb

  ├─a0
      197cf5327fec251ae14d063fb50d6d3e570674

  ├─a3
      d91d125103f57b7b60d7ebd6502aa0987828ab

  ├─b2
      7787b75a99a614f3b26fe482f0cd47bc3c186b

  ├─info
  └─pack

查看最新提交的 commit

git cat-file -p b27787      
# tree 654580c8026cf5b0ab07c5572f353409e3c83792
# parent a3d91d125103f57b7b60d7ebd6502aa0987828ab  (上一次提交)
# author Jack-Zhang-1314 <fwqaaq@gmail.com> 1656708529 +0800
# committer Jack-Zhang-1314 <fwqaaq@gmail.com> 1656708529 +0800
# 
# 2st commit

# tree中的内容依然会指向这两个文件
git cat-file -p 654580
# 100644 blob 80993781b54ed1b81e47a31e6427940c1a9deafb    hello.txt
# 100644 blob 190b00d560cb8ac4e17678e8fccc7a2af8057bdd    temp.txt

修改暂存区的文件

git cat-file -p 8099378
# hello world 
git cat-file -t 8099378
# blob

git 的文件状态