跳到主要内容

Git Internal

strobject typenumber
commitOBJ_COMMIT1
treeOBJ_TREE2
blobOBJ_BLOB3
tagOBJ_TAG4
OBJ_OFS_DELTA6
OBJ_REF_DELTA7
echo -n hello | git hash-object --stdin
# blob <size>\0
printf 'blob 5\0hello' | sha1sum
CONTENTS=hello sh -c 'printf "blob ${#CONTENTS}\0$CONTENTS"' | sha1sum

echo -n hello > /tmp/hello
file=/tmp/hello
(
stat --printf="blob %s\0" "$file"
cat "$file"
) | sha1sum
  • .git
    • HEAD
    • config
    • description
    • hooks/
    • info/
    • objects/
      • info/
      • pack/ - Git pack format
        • pack-.{pack,idx}
        • pack-.rev
        • pack-*.mtimes
        • multi-pack-index
    • refs/
#
git init /tmp/git
cd /tmp/git
echo -n hello | git hash-object -w --stdin
find .git/objects -type f
file .git/objects/b6/fc4c620b67d95f953a5c1c1230aaab5db5a1b0 # zlib compressed data
git cat-file -p b6fc4c620b67d95f953a5c1c1230aaab5db5a1b0
git cat-file -t b6fc4c620b67d95f953a5c1c1230aaab5db5a1b0 # blob

echo -n hello > hello.txt
git add hello.txt
git commit -m 'hello.txt'

git cat-file -p master^{tree} # hello.txt
find .git/objects -type f
git cat-file -t 04df07b08ca746b3167d0f1d1514e2f39a52c16c # tree
git cat-file -p 04df07b08ca746b3167d0f1d1514e2f39a52c16c
# 100644 blob b6fc4c620b67d95f953a5c1c1230aaab5db5a1b0 hello.txt
git cat-file -t d7ca319a50ed5fb97583cc0ef251d19b503caa6d # commit
git cat-file -p d7ca319a50ed5fb97583cc0ef251d19b503caa6d
# author wener <email> 1665103472 +0800
# committer wener <email> 1665103472 +0800
# gpgsig
#
# hello.txt

git write-tree
git update-index --cacheinfo 100644 $(git hash-object hello.txt) hello.txt

echo new > new.txt
git update-index --add new.txt
git write-tree

git cat-file -p $(git write-tree)

git read-tree --prefix=bak $(git write-tree)

echo 'commit' | git commit-tree $(git write-tree)
git cat-file -p dc1eb3

echo 'Second commit' | git commit-tree $(git write-tree) -p dc1eb3
git cat-file -p 8989b5
git log --stat 8989b5

sha256

[core]
repositoryFormatVersion = 1
[extensions]
objectFormat = sha256
compatObjectFormat = sha1