]>
Commit | Line | Data |
---|---|---|
48a8c26c | 1 | Git index format |
8c7d0517 NTND |
2 | ================ |
3 | ||
2de9b711 | 4 | == The Git index file has the following format |
8c7d0517 NTND |
5 | |
6 | All binary numbers are in network byte order. Version 2 is described | |
7 | here unless stated otherwise. | |
8 | ||
9 | - A 12-byte header consisting of | |
10 | ||
11 | 4-byte signature: | |
23fcc98f | 12 | The signature is { 'D', 'I', 'R', 'C' } (stands for "dircache") |
8c7d0517 NTND |
13 | |
14 | 4-byte version number: | |
15 | The current supported versions are 2 and 3. | |
16 | ||
17 | 32-bit number of index entries. | |
18 | ||
23fcc98f | 19 | - A number of sorted index entries (see below). |
8c7d0517 NTND |
20 | |
21 | - Extensions | |
22 | ||
23 | Extensions are identified by signature. Optional extensions can | |
48a8c26c | 24 | be ignored if Git does not understand them. |
8c7d0517 | 25 | |
48a8c26c | 26 | Git currently supports cached tree and resolve undo extensions. |
8c7d0517 NTND |
27 | |
28 | 4-byte extension signature. If the first byte is 'A'..'Z' the | |
29 | extension is optional and can be ignored. | |
30 | ||
31 | 32-bit size of the extension | |
32 | ||
33 | Extension data | |
34 | ||
35 | - 160-bit SHA-1 over the content of the index file before this | |
36 | checksum. | |
37 | ||
38 | == Index entry | |
39 | ||
40 | Index entries are sorted in ascending order on the name field, | |
23fcc98f JH |
41 | interpreted as a string of unsigned bytes (i.e. memcmp() order, no |
42 | localization, no special casing of directory separator '/'). Entries | |
43 | with the same name are sorted by their stage field. | |
8c7d0517 NTND |
44 | |
45 | 32-bit ctime seconds, the last time a file's metadata changed | |
46 | this is stat(2) data | |
47 | ||
48 | 32-bit ctime nanosecond fractions | |
49 | this is stat(2) data | |
50 | ||
51 | 32-bit mtime seconds, the last time a file's data changed | |
52 | this is stat(2) data | |
53 | ||
54 | 32-bit mtime nanosecond fractions | |
55 | this is stat(2) data | |
56 | ||
57 | 32-bit dev | |
58 | this is stat(2) data | |
59 | ||
60 | 32-bit ino | |
61 | this is stat(2) data | |
62 | ||
63 | 32-bit mode, split into (high to low bits) | |
64 | ||
65 | 4-bit object type | |
23fcc98f | 66 | valid values in binary are 1000 (regular file), 1010 (symbolic link) |
8c7d0517 NTND |
67 | and 1110 (gitlink) |
68 | ||
69 | 3-bit unused | |
70 | ||
23fcc98f JH |
71 | 9-bit unix permission. Only 0755 and 0644 are valid for regular files. |
72 | Symbolic links and gitlinks have value 0 in this field. | |
8c7d0517 NTND |
73 | |
74 | 32-bit uid | |
75 | this is stat(2) data | |
76 | ||
77 | 32-bit gid | |
78 | this is stat(2) data | |
79 | ||
80 | 32-bit file size | |
23fcc98f | 81 | This is the on-disk size from stat(2), truncated to 32-bit. |
8c7d0517 NTND |
82 | |
83 | 160-bit SHA-1 for the represented object | |
84 | ||
23fcc98f | 85 | A 16-bit 'flags' field split into (high to low bits) |
8c7d0517 NTND |
86 | |
87 | 1-bit assume-valid flag | |
88 | ||
89 | 1-bit extended flag (must be zero in version 2) | |
90 | ||
91 | 2-bit stage (during merge) | |
92 | ||
23fcc98f JH |
93 | 12-bit name length if the length is less than 0xFFF; otherwise 0xFFF |
94 | is stored in this field. | |
8c7d0517 NTND |
95 | |
96 | (Version 3) A 16-bit field, only applicable if the "extended flag" | |
97 | above is 1, split into (high to low bits). | |
98 | ||
99 | 1-bit reserved for future | |
100 | ||
101 | 1-bit skip-worktree flag (used by sparse checkout) | |
102 | ||
103 | 1-bit intent-to-add flag (used by "git add -N") | |
104 | ||
105 | 13-bit unused, must be zero | |
106 | ||
107 | Entry path name (variable length) relative to top level directory | |
108 | (without leading slash). '/' is used as path separator. The special | |
23fcc98f | 109 | path components ".", ".." and ".git" (without quotes) are disallowed. |
8c7d0517 NTND |
110 | Trailing slash is also disallowed. |
111 | ||
112 | The exact encoding is undefined, but the '.' and '/' characters | |
23fcc98f JH |
113 | are encoded in 7-bit ASCII and the encoding cannot contain a NUL |
114 | byte (iow, this is a UNIX pathname). | |
8c7d0517 | 115 | |
afd7bd22 JH |
116 | (Version 4) In version 4, the entry path name is prefix-compressed |
117 | relative to the path name for the previous entry (the very first | |
118 | entry is encoded as if the path name for the previous entry is an | |
119 | empty string). At the beginning of an entry, an integer N in the | |
120 | variable width encoding (the same encoding as the offset is encoded | |
121 | for OFS_DELTA pack entries; see pack-format.txt) is stored, followed | |
122 | by a NUL-terminated string S. Removing N bytes from the end of the | |
123 | path name for the previous entry, and replacing it with the string S | |
124 | yields the path name for this entry. | |
125 | ||
8c7d0517 NTND |
126 | 1-8 nul bytes as necessary to pad the entry to a multiple of eight bytes |
127 | while keeping the name NUL-terminated. | |
128 | ||
afd7bd22 JH |
129 | (Version 4) In version 4, the padding after the pathname does not |
130 | exist. | |
131 | ||
8c7d0517 NTND |
132 | == Extensions |
133 | ||
23fcc98f | 134 | === Cached tree |
8c7d0517 | 135 | |
23fcc98f | 136 | Cached tree extension contains pre-computed hashes for trees that can |
8c7d0517 NTND |
137 | be derived from the index. It helps speed up tree object generation |
138 | from index for a new commit. | |
139 | ||
140 | When a path is updated in index, the path must be invalidated and | |
141 | removed from tree cache. | |
142 | ||
23fcc98f | 143 | The signature for this extension is { 'T', 'R', 'E', 'E' }. |
8c7d0517 | 144 | |
23fcc98f JH |
145 | A series of entries fill the entire extension; each of which |
146 | consists of: | |
8c7d0517 | 147 | |
23fcc98f | 148 | - NUL-terminated path component (relative to its parent directory); |
8c7d0517 | 149 | |
23fcc98f JH |
150 | - ASCII decimal number of entries in the index that is covered by the |
151 | tree this entry represents (entry_count); | |
8c7d0517 | 152 | |
23fcc98f | 153 | - A space (ASCII 32); |
8c7d0517 | 154 | |
23fcc98f JH |
155 | - ASCII decimal number that represents the number of subtrees this |
156 | tree has; | |
8c7d0517 | 157 | |
23fcc98f JH |
158 | - A newline (ASCII 10); and |
159 | ||
160 | - 160-bit object name for the object that would result from writing | |
161 | this span of index as a tree. | |
162 | ||
e44b6df9 | 163 | An entry can be in an invalidated state and is represented by having |
4a6385fe NTND |
164 | a negative number in the entry_count field. In this case, there is no |
165 | object name and the next entry starts immediately after the newline. | |
166 | When writing an invalid entry, -1 should always be used as entry_count. | |
23fcc98f JH |
167 | |
168 | The entries are written out in the top-down, depth-first order. The | |
169 | first entry represents the root level of the repository, followed by the | |
170 | first subtree---let's call this A---of the root level (with its name | |
171 | relative to the root level), followed by the first subtree of A (with | |
172 | its name relative to A), ... | |
8c7d0517 NTND |
173 | |
174 | === Resolve undo | |
175 | ||
23fcc98f | 176 | A conflict is represented in the index as a set of higher stage entries. |
8c7d0517 | 177 | When a conflict is resolved (e.g. with "git add path"), these higher |
23fcc98f JH |
178 | stage entries will be removed and a stage-0 entry with proper resoluton |
179 | is added. | |
8c7d0517 | 180 | |
23fcc98f JH |
181 | When these higher stage entries are removed, they are saved in the |
182 | resolve undo extension, so that conflicts can be recreated (e.g. with | |
183 | "git checkout -m"), in case users want to redo a conflict resolution | |
184 | from scratch. | |
8c7d0517 | 185 | |
23fcc98f | 186 | The signature for this extension is { 'R', 'E', 'U', 'C' }. |
8c7d0517 | 187 | |
23fcc98f JH |
188 | A series of entries fill the entire extension; each of which |
189 | consists of: | |
8c7d0517 | 190 | |
23fcc98f JH |
191 | - NUL-terminated pathname the entry describes (relative to the root of |
192 | the repository, i.e. full pathname); | |
8c7d0517 | 193 | |
23fcc98f JH |
194 | - Three NUL-terminated ASCII octal numbers, entry mode of entries in |
195 | stage 1 to 3 (a missing stage is represented by "0" in this field); | |
196 | and | |
8c7d0517 | 197 | |
23fcc98f JH |
198 | - At most three 160-bit object names of the entry in stages from 1 to 3 |
199 | (nothing is written for a missing stage). | |
8c7d0517 | 200 |