Skip to content

Commit 031ee54

Browse files
bk2204gitster
authored andcommitted
docs: add documentation for loose objects
We currently have no documentation for how loose objects are stored. Let's add some here so its easy for people to understand how they work. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d5d2250 commit 031ee54

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Documentation/gitformat-loose.adoc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
gitformat-loose(5)
2+
==================
3+
4+
NAME
5+
----
6+
gitformat-loose - Git loose object format
7+
8+
9+
SYNOPSIS
10+
--------
11+
[verse]
12+
$GIT_DIR/objects/[0-9a-f][0-9a-f]/*
13+
$GIT_DIR/objects/loose-object-idx
14+
$GIT_DIR/objects/loose-map/map-*.map
15+
16+
DESCRIPTION
17+
-----------
18+
19+
Loose objects are how Git initially stores most of its primary repository data.
20+
Over the lifetime of a repository, objects are usually written as loose objects
21+
initially and then converted into packs.
22+
23+
== Loose objects
24+
25+
Each loose object contains a prefix, followed immediately by the data of the
26+
object. The prefix contains `<type> <size>\0`. `<type>` is one of `blob`,
27+
`tree`, `commit`, or `tag` and `size` is the size of the data (without the
28+
prefix) as a decimal integer expressed in ASCII.
29+
30+
The entire contents, prefix and data concatenated, is then compressed with zlib
31+
and the compressed data is stored in the file. The object ID of the object is
32+
the SHA-1 or SHA-256 (as appropriate) hash of the uncompressed data.
33+
34+
The file for the loose object is stored under the `objects` directory, with the
35+
first two hex characters of the object ID being the directory and the remaining
36+
characters being the file name.
37+
38+
As an example, the empty tree contains the data (when uncompressed) `tree 0\0`
39+
and, in a SHA-256 repository, would have the object ID
40+
`6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321` and would be
41+
stored under
42+
`$GIT_DIR/objects/6e/f19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321`.
43+
44+
Similarly, a blob containing the contents `abc` would have the uncompressed
45+
data of `blob 3\0abc`.
46+
47+
GIT
48+
---
49+
Part of the linkgit:git[1] suite

0 commit comments

Comments
 (0)