1 GIT index format
2 ================
4 = The git index file has the following format
6 All binary numbers are in network byte order. Version 2 is described
7 here unless stated otherwise.
9 - A 12-byte header consisting of
11 4-byte signature:
12 The signature is { 'D', 'I', 'R', 'C' }
14 4-byte version number:
15 The current supported versions are 2 and 3.
17 32-bit number of index entries.
19 - A number of sorted index entries
21 - Extensions
23 Extensions are identified by signature. Optional extensions can
24 be ignored if GIT does not understand them.
26 GIT currently supports tree cache and resolve undo extensions.
28 4-byte extension signature. If the first byte is 'A'..'Z' the
29 extension is optional and can be ignored.
31 32-bit size of the extension
33 Extension data
35 - 160-bit SHA-1 over the content of the index file before this
36 checksum.
38 == Index entry
40 Index entries are sorted in ascending order on the name field,
41 interpreted as a string of unsigned bytes. Entries with the same
42 name are sorted by their stage field.
44 32-bit ctime seconds, the last time a file's metadata changed
45 this is stat(2) data
47 32-bit ctime nanosecond fractions
48 this is stat(2) data
50 32-bit mtime seconds, the last time a file's data changed
51 this is stat(2) data
53 32-bit mtime nanosecond fractions
54 this is stat(2) data
56 32-bit dev
57 this is stat(2) data
59 32-bit ino
60 this is stat(2) data
62 32-bit mode, split into (high to low bits)
64 4-bit object type
65 valid values in binary are 1000 (blob), 1010 (symbolic link)
66 and 1110 (gitlink)
68 3-bit unused
70 9-bit unix permission (only 0755 and 0644 are valid)
72 32-bit uid
73 this is stat(2) data
75 32-bit gid
76 this is stat(2) data
78 32-bit file size
79 This is the on-disk size from stat(2)
81 160-bit SHA-1 for the represented object
83 A 16-bit field split into (high to low bits)
85 1-bit assume-valid flag
87 1-bit extended flag (must be zero in version 2)
89 2-bit stage (during merge)
91 12-bit name length if the length is less than 0x0FFF
93 (Version 3) A 16-bit field, only applicable if the "extended flag"
94 above is 1, split into (high to low bits).
96 1-bit reserved for future
98 1-bit skip-worktree flag (used by sparse checkout)
100 1-bit intent-to-add flag (used by "git add -N")
102 13-bit unused, must be zero
104 Entry path name (variable length) relative to top level directory
105 (without leading slash). '/' is used as path separator. The special
106 paths ".", ".." and ".git" (without quotes) are disallowed.
107 Trailing slash is also disallowed.
109 The exact encoding is undefined, but the '.' and '/' characters
110 are encoded in 7-bit ASCII and the encoding cannot contain a nul
111 byte. Generally a superset of ASCII.
113 1-8 nul bytes as necessary to pad the entry to a multiple of eight bytes
114 while keeping the name NUL-terminated.
116 == Extensions
118 === Tree cache
120 Tree cache extension contains pre-computed hashes for trees that can
121 be derived from the index. It helps speed up tree object generation
122 from index for a new commit.
124 When a path is updated in index, the path must be invalidated and
125 removed from tree cache.
127 - Extension tag { 'T', 'R', 'E', 'E' }
129 - 32-bit size
131 - A number of entries
133 NUL-terminated tree name
135 Blank-terminated ASCII decimal number of entries in this tree
137 Newline-terminated position of this tree in the parent tree. 0 for
138 the root tree
140 160-bit SHA-1 for this tree and it's children
142 === Resolve undo
144 A conflict is represented in index as a set of higher stage entries.
145 When a conflict is resolved (e.g. with "git add path"), these higher
146 stage entries will be removed and a stage-0 entry with proper
147 resoluton is added.
149 Resolve undo extension saves these higher stage entries so that
150 conflicts can be recreated (e.g. with "git checkout -m"), in case
151 users want to redo a conflict resolution from scratch.
153 - Extension tag { 'R', 'E', 'U', 'C' }
155 - 32-bit size
157 - A number of conflict entries
159 NUL-terminated conflict path
161 Three NUL-terminated ASCII octal numbers, entry mode of entries in
162 stage 1 to 3.
164 At most three 160-bit SHA-1s of the entry in three stages from 1
165 to 3. SHA-1 is not saved for any stage with entry mode zero.