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
12 The signature is { 'D', 'I', 'R', 'C' } (stands for "dircache")
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 (see below).
23 Extensions are identified by signature. Optional extensions can
24 be ignored if GIT does not understand them.
26 GIT currently supports cached tree 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
35 - 160-bit SHA-1 over the content of the index file before this
40 Index entries are sorted in ascending order on the name field,
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.
45 32-bit ctime seconds, the last time a file's metadata changed
48 32-bit ctime nanosecond fractions
51 32-bit mtime seconds, the last time a file's data changed
54 32-bit mtime nanosecond fractions
63 32-bit mode, split into (high to low bits)
66 valid values in binary are 1000 (regular file), 1010 (symbolic link)
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.
81 This is the on-disk size from stat(2), truncated to 32-bit.
83 160-bit SHA-1 for the represented object
85 A 16-bit 'flags' field split into (high to low bits)
87 1-bit assume-valid flag
89 1-bit extended flag (must be zero in version 2)
91 2-bit stage (during merge)
93 12-bit name length if the length is less than 0xFFF; otherwise 0xFFF
94 is stored in this field.
96 (Version 3) A 16-bit field, only applicable if the "extended flag"
97 above is 1, split into (high to low bits).
99 1-bit reserved for future
101 1-bit skip-worktree flag (used by sparse checkout)
103 1-bit intent-to-add flag (used by "git add -N")
105 13-bit unused, must be zero
107 Entry path name (variable length) relative to top level directory
108 (without leading slash). '/' is used as path separator. The special
109 path components ".", ".." and ".git" (without quotes) are disallowed.
110 Trailing slash is also disallowed.
112 The exact encoding is undefined, but the '.' and '/' characters
113 are encoded in 7-bit ASCII and the encoding cannot contain a NUL
114 byte (iow, this is a UNIX pathname).
116 1-8 nul bytes as necessary to pad the entry to a multiple of eight bytes
117 while keeping the name NUL-terminated.
123 Cached tree extension contains pre-computed hashes for trees that can
124 be derived from the index. It helps speed up tree object generation
125 from index for a new commit.
127 When a path is updated in index, the path must be invalidated and
128 removed from tree cache.
130 The signature for this extension is { 'T', 'R', 'E', 'E' }.
132 A series of entries fill the entire extension; each of which
135 - NUL-terminated path component (relative to its parent directory);
137 - ASCII decimal number of entries in the index that is covered by the
138 tree this entry represents (entry_count);
140 - A space (ASCII 32);
142 - ASCII decimal number that represents the number of subtrees this
145 - A newline (ASCII 10); and
147 - 160-bit object name for the object that would result from writing
148 this span of index as a tree.
150 An entry can be in an invalidated state and is represented by having
151 -1 in the entry_count field. In this case, there is no object name
152 and the next entry starts immediately after the newline.
154 The entries are written out in the top-down, depth-first order. The
155 first entry represents the root level of the repository, followed by the
156 first subtree---let's call this A---of the root level (with its name
157 relative to the root level), followed by the first subtree of A (with
158 its name relative to A), ...
162 A conflict is represented in the index as a set of higher stage entries.
163 When a conflict is resolved (e.g. with "git add path"), these higher
164 stage entries will be removed and a stage-0 entry with proper resoluton
167 When these higher stage entries are removed, they are saved in the
168 resolve undo extension, so that conflicts can be recreated (e.g. with
169 "git checkout -m"), in case users want to redo a conflict resolution
172 The signature for this extension is { 'R', 'E', 'U', 'C' }.
174 A series of entries fill the entire extension; each of which
177 - NUL-terminated pathname the entry describes (relative to the root of
178 the repository, i.e. full pathname);
180 - Three NUL-terminated ASCII octal numbers, entry mode of entries in
181 stage 1 to 3 (a missing stage is represented by "0" in this field);
184 - At most three 160-bit object names of the entry in stages from 1 to 3
185 (nothing is written for a missing stage).