git-cat-file 命令

该命令用于显示指定对象的信息

命令格式

1
2
git cat-file (-t [--allow-unknown-type]| -s [--allow-unknown-type]| -e | -p | <type> | --textconv | --filters ) [--path=<path>] <object>
git cat-file (--batch | --batch-check) [ --textconv | --filters ] [--follow-symlinks]

命令参数选项

  • -t: 显示对象类型
  • -s: 显示对象大小(bytes)
  • -e: 如果对象存在且是有效的,则命令正常返回0;如果对象无效,则命令返回非零值,并在标准错误输入打印错误信息
  • -p: 显示对象内容
  • –batch: 从标准输入读取对象id,显示对象信息(类型、大小)和对象内容
  • –batch-check: 从标准输入读取对象id,显示对象信息(类型、大小)

例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[root@localhost gitNewTest]# find .git/objects/ -type f
.git/objects/3b/18e512dba79e4c8300dd08aeb37f8e728b8dad
[root@localhost gitNewTest]# git cat-file -p 3b18e512
hello world
[root@localhost gitNewTest]# git cat-file -s 3b18e512
12
[root@localhost gitNewTest]# git cat-file -t 3b18e512
blob
[root@localhost gitNewTest]# git cat-file -e 3b18e512
[root@localhost gitNewTest]# echo $?
0
[root@localhost gitNewTest]# git cat-file -e 3b18e513
fatal: Not a valid object name 3b18e513
[root@localhost gitNewTest]# echo $?
128
[root@localhost gitNewTest]# git cat-file -t 3b18e513
fatal: Not a valid object name 3b18e513
[root@localhost gitNewTest]# echo $?
128
[root@localhost gitNewTest]# git cat-file --batch
3b18e512
3b18e512dba79e4c8300dd08aeb37f8e728b8dad blob 12
hello world

33333
33333 missing
^C
[root@localhost gitNewTest]# git cat-file --batch-check
3b18e512
3b18e512dba79e4c8300dd08aeb37f8e728b8dad blob 12
adces
adces missing
^C
[root@localhost gitNewTest]#