Git articles reading notes 2

Git series 1/3: Understanding git for real by exploring the .git directory

Summary

  • Not just git commit/push

  • .git folder contains all the information Git needs. It’s structure after git init is similar to:


├── HEAD

├── branches

├── config

├── description

├── hooks

│ ├── pre-commit.sample

│ ├── pre-push.sample

│ └── ...

├── info

│ └── exclude

├── objects

│ ├── info

│ └── pack

└── refs

├── heads

└── tags
  • What’s inside a commit?

A commit is basically snapshot of your working directory, but it is a bit more than that.


$ git log -n 2 --stat

commit e851cc9ed9693a716a9ff737e4973b7e72133188 (HEAD -> daily)

Author: hustnzj <27875723+hustnzj@users.noreply.github.com>

Date: Tue Aug 30 17:26:38 2022 +0800

good-articles: Git 日益精进 1

Git/good articles/good articles read summary.md | 22 ++++++++++++++++++++++

Git/good articles/pending.md | 6 ++++++

todos.md | 8 +++++---

3 files changed, 33 insertions(+), 3 deletions(-)

commit dc36721071a6046b7ec33cdaabdf5b4cb80eec85 (main)

Author: hustnzj <27875723+hustnzj@users.noreply.github.com>

Date: Tue Aug 30 13:01:56 2022 +0800

clean up the project directory

Git/{useful_experience.md => useful_experiences/How to edit, delete existing commits in Git.md} | 0

1 file changed, 0 insertions(+), 0 deletions(-)

$ git cat-file -p e851cc9ed9693a716a9ff737e4973b7e72133188

tree b665c53ebc28041bbfd3ba45620afefe7a7d899c ## the name(hash) of snapshot of your working directory

parent dc36721071a6046b7ec33cdaabdf5b4cb80eec85 ## the name of parent of last commit

author hustnzj <27875723+hustnzj@users.noreply.github.com> 1661851598 +0800 ## author information

committer hustnzj <27875723+hustnzj@users.noreply.github.com> 1661851598 +0800 ## Commiter information

$ git cat-file -p b665c53ebc28041bbfd3ba45620afefe7a7d899c ## snapshot of your working directory

100644 blob 642ca81be856fd067a3cce14067638552717db70 .gitattributes

100644 blob fbcff670a686f9552a962226d04a2c6bc21bcb70 .gitignore

100644 blob 53f50401b69793ddaf9ebfdac50261f457b7df73 .gitmodules

040000 tree 127de22832fcf99d0543266e2a01afd5b5bb9209 .vscode

040000 tree 6914ef191d779bcff90e2a634d7cd13e2f2e0ab4 PHP

040000 tree d29872fb64a9294cd6632c05685ec0107f9b66e9 Git

(...)
  • What happened in a commit?

Every-time you create a file, and track it, git compresses it and stores it into its own data structure. The compressed object will have a unique name, a hash, and will be stored under the object directory.

How to find the objects?


$ ll -t | head -n 10

total 0

drwxr-xr-x 8 administrator staff 256B Aug 30 17:26 e8

drwxr-xr-x 11 administrator staff 352B Aug 30 17:26 b6

drwxr-xr-x 8 administrator staff 256B Aug 30 17:26 d2

drwxr-xr-x 8 administrator staff 256B Aug 30 17:26 f8

drwxr-xr-x 6 administrator staff 192B Aug 30 17:25 f3

drwxr-xr-x 8 administrator staff 256B Aug 30 17:25 f5

drwxr-xr-x 8 administrator staff 256B Aug 30 17:25 0c

drwxr-xr-x 8 administrator staff 256B Aug 30 13:01 dc

drwxr-xr-x 8 administrator staff 256B Aug 30 13:01 c2

Matched the 17:26 in the last commit time.

Found the four objects using ll -t e8 b6 d2 f8:


e8:

total 48

-r--r--r-- 1 administrator staff 207B Aug 30 17:26 51cc9ed9693a716a9ff737e4973b7e72133188

-r--r--r-- 1 administrator staff 85B Aug 29 07:00 a0ada9f70d5c7565e07db7be58a0e1e7fad429

-r--r--r-- 1 administrator staff 126B Aug 29 07:00 178e4778c940911efee71a3bff3f3423dbbe48

-r--r--r-- 1 administrator staff 188B Aug 29 07:00 f5e3d42538c9e403480a5ee57169b65583e0ce

-r--r--r-- 1 administrator staff 513B Aug 29 07:00 cc9f6b66a8b1b5c3fcc6f8e566a4fd04550037

-r--r--r-- 1 administrator staff 56B Aug 29 07:00 51ab6b41eea79629d0f662800682d8a12e5bd6

b6:

total 24984

-r--r--r-- 1 administrator staff 1.1K Aug 30 17:26 65c53ebc28041bbfd3ba45620afefe7a7d899c

-r--r--r-- 1 administrator staff 466B Aug 30 11:24 9829b54901cc7c7e4354be645acc6d0d1c53f6

-r--r--r-- 1 administrator staff 2.7K Aug 29 07:00 36975b7d0c685bc4e6ba6488988b3c9f3b4d1c

-r--r--r-- 1 administrator staff 2.5K Aug 29 07:00 9b59ac9de1f23c2afec74c21cab3a51f840a39

-r--r--r-- 1 administrator staff 68B Aug 29 07:00 005da89ab2470478fb72f61863bf41dcab4725

-r--r--r-- 1 administrator staff 87B Aug 29 07:00 5079a06644768f36d08fe08e9bb0c967670ae0

-r--r--r-- 1 administrator staff 1.4K Aug 29 07:00 630e527d77f2889a6c558e602f9cd1971923b3

-r--r--r-- 1 administrator staff 12M Aug 29 07:00 09e6f4a445b74f5452aaedf4da6d3c8d5e186c

-r--r--r-- 1 administrator staff 176B Aug 29 07:00 64cb18199eba5bedd5662518e522e7ae2116ad

d2:

total 48

-r--r--r-- 1 administrator staff 190B Aug 30 17:26 9872fb64a9294cd6632c05685ec0107f9b66e9

-r--r--r-- 1 administrator staff 162B Aug 29 07:00 74d3c5ad5e849c4668722d5269d14f49bbe410

-r--r--r-- 1 administrator staff 54B Aug 29 07:00 d3fda3d3cb44812bc19604a4634787774f09b1

-r--r--r-- 1 administrator staff 84B Aug 29 07:00 ea1846e1e93c06be9aa91d21d3956892d51eac

-r--r--r-- 1 administrator staff 82B Aug 29 07:00 7be1734450d5fee21d5198d3fc15af02584de2

-r--r--r-- 1 administrator staff 129B Aug 29 07:00 dd12be6597a6f91ca0d26d937be0a8af58a1c4

f8:

total 336

-r--r--r-- 1 administrator staff 106B Aug 30 17:26 5c9f643a589c73ed188a8fd0a63d192e1469a2

-r--r--r-- 1 administrator staff 1.6K Aug 29 07:00 4f591d62283b2b4efbf6a86d25301bfd895cd9

-r--r--r-- 1 administrator staff 126B Aug 29 07:00 ae47d734fde50ce03f3844e9c822c75c772ddf

-r--r--r-- 1 administrator staff 145K Aug 29 07:00 f6fb16b3aa66f9ad5938d96475c3603e96469a

-r--r--r-- 1 administrator staff 210B Aug 29 07:00 43cc5adaf73503133c3f202653849b58b0ab5d

-r--r--r-- 1 administrator staff 158B Aug 29 07:00 3bda51ddefe37bfcdf32cb604d5750e7445f74

The detail study of the objects will be done in future.

  • branches, tags and HEAD are nothing more than a pointer to a commit.

$ cat HEAD

ref: refs/heads/daily

$ cat refs/heads/daily

e851cc9ed9693a716a9ff737e4973b7e72133188

$ git log -n 1 --oneline

commit e851cc9ed9693a716a9ff737e4973b7e72133188 (HEAD -> daily)

Author: hustnzj <27875723+hustnzj@users.noreply.github.com>

Date: Tue Aug 30 17:26:38 2022 +0800

good-articles: Git 日益精进 1
本作品采用《CC 协议》,转载必须注明作者和本文链接
日拱一卒
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
未填写
文章
93
粉丝
85
喜欢
153
收藏
121
排名:71
访问:11.4 万
私信
所有博文
社区赞助商