1. .git/objects
目录
git
是一个根据文件内容进行检索的系统。 当创建 hello.py
, 填入
print("hello, world")
的内容, 并执行
git add hello.py
git commit -m "init"
会在 .git/objects
目录生成子目录和文件。 子目录是2位,文件则是38位, 子目录和文件名字拼接起来的到的40位哈希码, 就是 SHA-1:
比较新版本的 git
, 当执行上述 git 操作后, 会在 .git/objects
里存储多个子目录, 旧版本的 git 则只生成一个子目录。我用的 git 2.45.2, 目录结构为:
2. git cat-file
命令
git cat-file
命令能查看 sha-1
的情况, 这里暂时未查阅文档, 仅做基本介绍。
git cat-file -t <sha-1>
查看的是 sha-1
的类型。 其中 sha-1
是子目录和文件拼接起来的。例如
➜ test git:(main) ✗ git cat-file -t 8cde7829c178ede96040e03f17c416d15bdacd01
blob
git cat-file -p <sha-1>
则是查看 blob 类型的内容:
➜ test git:(main) ✗ git cat-file -p 8cde7829c178ede96040e03f17c416d15bdacd01
print("hello world")