>> >> >> Reference << << << <<<<<<Ref>>>>>>
cat-file
Modified: 2025-12-31 | Author:ljf12825

git cat-file用于查看Git对象的内容。Git中的对象(如提交对象、树对象、Blob对象等)以二进制格式存储,git cat-file允许以可读的形式查看这些对象的内容

常见用法

  1. 查看对象内容
git cat-file commit <commit_hash> 

这将显示指定commit的内容,包括提交信息、父提交、作者和提交者等

  1. 查看树对象
git cat-file tree <tree_hash> 

这将显示树对象的内容,包括该提交所指向的所有文件和目录的对象ID

  1. 查看Blob对象
git cat-file blob <blob_hash>

这将显示文件内容,如果该对象是一个文件,git cat-file会输出其内容

  1. 查看Git对象的类型和大小
git cat-file -t <object_hash> # 显示对象的类型
git cat-file -s <object_hash> # 显示对象的大小
  1. 显示
git cat-file -p <sha> # 漂亮地打印对象内容
git cat-file <type> <sha> # 显示type原始数据

适用场景