|
| 1 | +gitrepository-layout(5) |
| 2 | +======================= |
| 3 | + |
| 4 | +NAME |
| 5 | +---- |
| 6 | +gitrepository-layout - Git Repository Layout |
| 7 | + |
| 8 | +SYNOPSIS |
| 9 | +-------- |
| 10 | +$GIT_DIR/* |
| 11 | + |
| 12 | +DESCRIPTION |
| 13 | +----------- |
| 14 | + |
| 15 | +A Git repository comes in two different flavours: |
| 16 | + |
| 17 | + * a `.git` directory at the root of the working tree; |
| 18 | + |
| 19 | + * a `<project>.git` directory that is a 'bare' repository |
| 20 | + (i.e. without its own working tree), that is typically used for |
| 21 | + exchanging histories with others by pushing into it and fetching |
| 22 | + from it. |
| 23 | + |
| 24 | +*Note*: Also you can have a plain text file `.git` at the root of |
| 25 | +your working tree, containing `gitdir: <path>` to point at the real |
| 26 | +directory that has the repository. |
| 27 | +This mechanism is called a 'gitfile' and is usually managed via the |
| 28 | +`git submodule` and `git worktree` commands. It is often used for |
| 29 | +a working tree of a submodule checkout, to allow you in the |
| 30 | +containing superproject to `git checkout` a branch that does not |
| 31 | +have the submodule. The `checkout` has to remove the entire |
| 32 | +submodule working tree, without losing the submodule repository. |
| 33 | + |
| 34 | +These things may exist in a Git repository. |
| 35 | + |
| 36 | +objects:: |
| 37 | + Object store associated with this repository. Usually |
| 38 | + an object store is self sufficient (i.e. all the objects |
| 39 | + that are referred to by an object found in it are also |
| 40 | + found in it), but there are a few ways to violate it. |
| 41 | ++ |
| 42 | +. You could have an incomplete but locally usable repository |
| 43 | +by creating a shallow clone. See linkgit:git-clone[1]. |
| 44 | +. You could be using the `objects/info/alternates` or |
| 45 | +`$GIT_ALTERNATE_OBJECT_DIRECTORIES` mechanisms to 'borrow' |
| 46 | +objects from other object stores. A repository with this kind |
| 47 | +of incomplete object store is not suitable to be published for |
| 48 | +use with dumb transports but otherwise is OK as long as |
| 49 | +`objects/info/alternates` points at the object stores it |
| 50 | +borrows from. |
| 51 | ++ |
| 52 | +This directory is ignored if $GIT_COMMON_DIR is set and |
| 53 | +"$GIT_COMMON_DIR/objects" will be used instead. |
| 54 | + |
| 55 | +objects/[0-9a-f][0-9a-f]:: |
| 56 | + A newly created object is stored in its own file. |
| 57 | + The objects are splayed over 256 subdirectories using |
| 58 | + the first two characters of the sha1 object name to |
| 59 | + keep the number of directory entries in `objects` |
| 60 | + itself to a manageable number. Objects found |
| 61 | + here are often called 'unpacked' (or 'loose') objects. |
| 62 | + |
| 63 | +objects/pack:: |
| 64 | + Packs (files that store many objects in compressed form, |
| 65 | + along with index files to allow them to be randomly |
| 66 | + accessed) are found in this directory. |
| 67 | + |
| 68 | +objects/info:: |
| 69 | + Additional information about the object store is |
| 70 | + recorded in this directory. |
| 71 | + |
| 72 | +objects/info/packs:: |
| 73 | + This file is to help dumb transports discover what packs |
| 74 | + are available in this object store. Whenever a pack is |
| 75 | + added or removed, `git update-server-info` should be run |
| 76 | + to keep this file up to date if the repository is |
| 77 | + published for dumb transports. 'git repack' does this |
| 78 | + by default. |
| 79 | + |
| 80 | +objects/info/alternates:: |
| 81 | + This file records paths to alternate object stores that |
| 82 | + this object store borrows objects from, one pathname per |
| 83 | + line. Note that not only native Git tools use it locally, |
| 84 | + but the HTTP fetcher also tries to use it remotely; this |
| 85 | + will usually work if you have relative paths (relative |
| 86 | + to the object database, not to the repository!) in your |
| 87 | + alternates file, but it will not work if you use absolute |
| 88 | + paths unless the absolute path in filesystem and web URL |
| 89 | + is the same. See also `objects/info/http-alternates`. |
| 90 | + |
| 91 | +objects/info/http-alternates:: |
| 92 | + This file records URLs to alternate object stores that |
| 93 | + this object store borrows objects from, to be used when |
| 94 | + the repository is fetched over HTTP. |
| 95 | + |
| 96 | +refs:: |
| 97 | + References are stored in subdirectories of this |
| 98 | + directory. The 'git prune' command knows to preserve |
| 99 | + objects reachable from refs found in this directory and |
| 100 | + its subdirectories. |
| 101 | + This directory is ignored (except refs/bisect, |
| 102 | + refs/rewritten and refs/worktree) if $GIT_COMMON_DIR is |
| 103 | + set and "$GIT_COMMON_DIR/refs" will be used instead. |
| 104 | + |
| 105 | +refs/heads/`name`:: |
| 106 | + records tip-of-the-tree commit objects of branch `name` |
| 107 | + |
| 108 | +refs/tags/`name`:: |
| 109 | + records any object name (not necessarily a commit |
| 110 | + object, or a tag object that points at a commit object). |
| 111 | + |
| 112 | +refs/remotes/`name`:: |
| 113 | + records tip-of-the-tree commit objects of branches copied |
| 114 | + from a remote repository. |
| 115 | + |
| 116 | +refs/replace/`<obj-sha1>`:: |
| 117 | + records the SHA-1 of the object that replaces `<obj-sha1>`. |
| 118 | + This is similar to info/grafts and is internally used and |
| 119 | + maintained by linkgit:git-replace[1]. Such refs can be exchanged |
| 120 | + between repositories while grafts are not. |
| 121 | + |
| 122 | +packed-refs:: |
| 123 | + records the same information as refs/heads/, refs/tags/, |
| 124 | + and friends record in a more efficient way. See |
| 125 | + linkgit:git-pack-refs[1]. This file is ignored if $GIT_COMMON_DIR |
| 126 | + is set and "$GIT_COMMON_DIR/packed-refs" will be used instead. |
| 127 | + |
| 128 | +HEAD:: |
| 129 | + A symref (see glossary) to the `refs/heads/` namespace |
| 130 | + describing the currently active branch. It does not mean |
| 131 | + much if the repository is not associated with any working tree |
| 132 | + (i.e. a 'bare' repository), but a valid Git repository |
| 133 | + *must* have the HEAD file; some porcelains may use it to |
| 134 | + guess the designated "default" branch of the repository |
| 135 | + (usually 'master'). It is legal if the named branch |
| 136 | + 'name' does not (yet) exist. In some legacy setups, it is |
| 137 | + a symbolic link instead of a symref that points at the current |
| 138 | + branch. |
| 139 | ++ |
| 140 | +HEAD can also record a specific commit directly, instead of |
| 141 | +being a symref to point at the current branch. Such a state |
| 142 | +is often called 'detached HEAD.' See linkgit:git-checkout[1] |
| 143 | +for details. |
| 144 | + |
| 145 | +config:: |
| 146 | + Repository specific configuration file. This file is ignored |
| 147 | + if $GIT_COMMON_DIR is set and "$GIT_COMMON_DIR/config" will be |
| 148 | + used instead. |
| 149 | + |
| 150 | +config.worktree:: |
| 151 | + Working directory specific configuration file for the main |
| 152 | + working directory in multiple working directory setup (see |
| 153 | + linkgit:git-worktree[1]). |
| 154 | + |
| 155 | +branches:: |
| 156 | + A slightly deprecated way to store shorthands to be used |
| 157 | + to specify a URL to 'git fetch', 'git pull' and 'git push'. |
| 158 | + A file can be stored as `branches/<name>` and then |
| 159 | + 'name' can be given to these commands in place of |
| 160 | + 'repository' argument. See the REMOTES section in |
| 161 | + linkgit:git-fetch[1] for details. This mechanism is legacy |
| 162 | + and not likely to be found in modern repositories. This |
| 163 | + directory is ignored if $GIT_COMMON_DIR is set and |
| 164 | + "$GIT_COMMON_DIR/branches" will be used instead. |
| 165 | + |
| 166 | + |
| 167 | +hooks:: |
| 168 | + Hooks are customization scripts used by various Git |
| 169 | + commands. A handful of sample hooks are installed when |
| 170 | + 'git init' is run, but all of them are disabled by |
| 171 | + default. To enable, the `.sample` suffix has to be |
| 172 | + removed from the filename by renaming. |
| 173 | + Read linkgit:githooks[5] for more details about |
| 174 | + each hook. This directory is ignored if $GIT_COMMON_DIR is set |
| 175 | + and "$GIT_COMMON_DIR/hooks" will be used instead. |
| 176 | + |
| 177 | +common:: |
| 178 | + When multiple working trees are used, most of files in |
| 179 | + $GIT_DIR are per-worktree with a few known exceptions. All |
| 180 | + files under 'common' however will be shared between all |
| 181 | + working trees. |
| 182 | + |
| 183 | +index:: |
| 184 | + The current index file for the repository. It is |
| 185 | + usually not found in a bare repository. |
| 186 | + |
| 187 | +sharedindex.<SHA-1>:: |
| 188 | + The shared index part, to be referenced by $GIT_DIR/index and |
| 189 | + other temporary index files. Only valid in split index mode. |
| 190 | + |
| 191 | +info:: |
| 192 | + Additional information about the repository is recorded |
| 193 | + in this directory. This directory is ignored if $GIT_COMMON_DIR |
| 194 | + is set and "$GIT_COMMON_DIR/info" will be used instead. |
| 195 | + |
| 196 | +info/refs:: |
| 197 | + This file helps dumb transports discover what refs are |
| 198 | + available in this repository. If the repository is |
| 199 | + published for dumb transports, this file should be |
| 200 | + regenerated by 'git update-server-info' every time a tag |
| 201 | + or branch is created or modified. This is normally done |
| 202 | + from the `hooks/update` hook, which is run by the |
| 203 | + 'git-receive-pack' command when you 'git push' into the |
| 204 | + repository. |
| 205 | + |
| 206 | +info/grafts:: |
| 207 | + This file records fake commit ancestry information, to |
| 208 | + pretend the set of parents a commit has is different |
| 209 | + from how the commit was actually created. One record |
| 210 | + per line describes a commit and its fake parents by |
| 211 | + listing their 40-byte hexadecimal object names separated |
| 212 | + by a space and terminated by a newline. |
| 213 | ++ |
| 214 | +Note that the grafts mechanism is outdated and can lead to problems |
| 215 | +transferring objects between repositories; see linkgit:git-replace[1] |
| 216 | +for a more flexible and robust system to do the same thing. |
| 217 | + |
| 218 | +info/exclude:: |
| 219 | + This file, by convention among Porcelains, stores the |
| 220 | + exclude pattern list. `.gitignore` is the per-directory |
| 221 | + ignore file. 'git status', 'git add', 'git rm' and |
| 222 | + 'git clean' look at it but the core Git commands do not look |
| 223 | + at it. See also: linkgit:gitignore[5]. |
| 224 | + |
| 225 | +info/attributes:: |
| 226 | + Defines which attributes to assign to a path, similar to per-directory |
| 227 | + `.gitattributes` files. See also: linkgit:gitattributes[5]. |
| 228 | + |
| 229 | +info/sparse-checkout:: |
| 230 | + This file stores sparse checkout patterns. |
| 231 | + See also: linkgit:git-read-tree[1]. |
| 232 | + |
| 233 | +remotes:: |
| 234 | + Stores shorthands for URL and default refnames for use |
| 235 | + when interacting with remote repositories via 'git fetch', |
| 236 | + 'git pull' and 'git push' commands. See the REMOTES section |
| 237 | + in linkgit:git-fetch[1] for details. This mechanism is legacy |
| 238 | + and not likely to be found in modern repositories. This |
| 239 | + directory is ignored if $GIT_COMMON_DIR is set and |
| 240 | + "$GIT_COMMON_DIR/remotes" will be used instead. |
| 241 | + |
| 242 | +logs:: |
| 243 | + Records of changes made to refs are stored in this directory. |
| 244 | + See linkgit:git-update-ref[1] for more information. This |
| 245 | + directory is ignored (except logs/HEAD) if $GIT_COMMON_DIR is |
| 246 | + set and "$GIT_COMMON_DIR/logs" will be used instead. |
| 247 | + |
| 248 | +logs/refs/heads/`name`:: |
| 249 | + Records all changes made to the branch tip named `name`. |
| 250 | + |
| 251 | +logs/refs/tags/`name`:: |
| 252 | + Records all changes made to the tag named `name`. |
| 253 | + |
| 254 | +shallow:: |
| 255 | + This is similar to `info/grafts` but is internally used |
| 256 | + and maintained by shallow clone mechanism. See `--depth` |
| 257 | + option to linkgit:git-clone[1] and linkgit:git-fetch[1]. This |
| 258 | + file is ignored if $GIT_COMMON_DIR is set and |
| 259 | + "$GIT_COMMON_DIR/shallow" will be used instead. |
| 260 | + |
| 261 | +commondir:: |
| 262 | + If this file exists, $GIT_COMMON_DIR (see linkgit:git[1]) will |
| 263 | + be set to the path specified in this file if it is not |
| 264 | + explicitly set. If the specified path is relative, it is |
| 265 | + relative to $GIT_DIR. The repository with commondir is |
| 266 | + incomplete without the repository pointed by "commondir". |
| 267 | + |
| 268 | +modules:: |
| 269 | + Contains the git-repositories of the submodules. |
| 270 | + |
| 271 | +worktrees:: |
| 272 | + Contains administrative data for linked |
| 273 | + working trees. Each subdirectory contains the working tree-related |
| 274 | + part of a linked working tree. This directory is ignored if |
| 275 | + $GIT_COMMON_DIR is set, in which case |
| 276 | + "$GIT_COMMON_DIR/worktrees" will be used instead. |
| 277 | + |
| 278 | +worktrees/<id>/gitdir:: |
| 279 | + A text file containing the absolute path back to the .git file |
| 280 | + that points to here. This is used to check if the linked |
| 281 | + repository has been manually removed and there is no need to |
| 282 | + keep this directory any more. The mtime of this file should be |
| 283 | + updated every time the linked repository is accessed. |
| 284 | + |
| 285 | +worktrees/<id>/locked:: |
| 286 | + If this file exists, the linked working tree may be on a |
| 287 | + portable device and not available. The presence of this file |
| 288 | + prevents `worktrees/<id>` from being pruned either automatically |
| 289 | + or manually by `git worktree prune`. The file may contain a string |
| 290 | + explaining why the repository is locked. |
| 291 | + |
| 292 | +worktrees/<id>/config.worktree:: |
| 293 | + Working directory specific configuration file. |
| 294 | + |
| 295 | +== Git Repository Format Versions |
| 296 | + |
| 297 | +Every git repository is marked with a numeric version in the |
| 298 | +`core.repositoryformatversion` key of its `config` file. This version |
| 299 | +specifies the rules for operating on the on-disk repository data. An |
| 300 | +implementation of git which does not understand a particular version |
| 301 | +advertised by an on-disk repository MUST NOT operate on that repository; |
| 302 | +doing so risks not only producing wrong results, but actually losing |
| 303 | +data. |
| 304 | + |
| 305 | +Because of this rule, version bumps should be kept to an absolute |
| 306 | +minimum. Instead, we generally prefer these strategies: |
| 307 | + |
| 308 | + - bumping format version numbers of individual data files (e.g., |
| 309 | + index, packfiles, etc). This restricts the incompatibilities only to |
| 310 | + those files. |
| 311 | + |
| 312 | + - introducing new data that gracefully degrades when used by older |
| 313 | + clients (e.g., pack bitmap files are ignored by older clients, which |
| 314 | + simply do not take advantage of the optimization they provide). |
| 315 | + |
| 316 | +A whole-repository format version bump should only be part of a change |
| 317 | +that cannot be independently versioned. For instance, if one were to |
| 318 | +change the reachability rules for objects, or the rules for locking |
| 319 | +refs, that would require a bump of the repository format version. |
| 320 | + |
| 321 | +Note that this applies only to accessing the repository's disk contents |
| 322 | +directly. An older client which understands only format `0` may still |
| 323 | +connect via `git://` to a repository using format `1`, as long as the |
| 324 | +server process understands format `1`. |
| 325 | + |
| 326 | +The preferred strategy for rolling out a version bump (whether whole |
| 327 | +repository or for a single file) is to teach git to read the new format, |
| 328 | +and allow writing the new format with a config switch or command line |
| 329 | +option (for experimentation or for those who do not care about backwards |
| 330 | +compatibility with older gits). Then after a long period to allow the |
| 331 | +reading capability to become common, we may switch to writing the new |
| 332 | +format by default. |
| 333 | + |
| 334 | +The currently defined format versions are: |
| 335 | + |
| 336 | +=== Version `0` |
| 337 | + |
| 338 | +This is the format defined by the initial version of git, including but |
| 339 | +not limited to the format of the repository directory, the repository |
| 340 | +configuration file, and the object and ref storage. Specifying the |
| 341 | +complete behavior of git is beyond the scope of this document. |
| 342 | + |
| 343 | +=== Version `1` |
| 344 | + |
| 345 | +This format is identical to version `0`, with the following exceptions: |
| 346 | + |
| 347 | + 1. When reading the `core.repositoryformatversion` variable, a git |
| 348 | + implementation which supports version 1 MUST also read any |
| 349 | + configuration keys found in the `extensions` section of the |
| 350 | + configuration file. |
| 351 | + |
| 352 | + 2. If a version-1 repository specifies any `extensions.*` keys that |
| 353 | + the running git has not implemented, the operation MUST NOT |
| 354 | + proceed. Similarly, if the value of any known key is not understood |
| 355 | + by the implementation, the operation MUST NOT proceed. |
| 356 | + |
| 357 | +Note that if no extensions are specified in the config file, then |
| 358 | +`core.repositoryformatversion` SHOULD be set to `0` (setting it to `1` |
| 359 | +provides no benefit, and makes the repository incompatible with older |
| 360 | +implementations of git). |
| 361 | + |
| 362 | +The defined extensions are given in the `extensions.*` section of |
| 363 | +linkgit:git-config[1]. Any implementation wishing to define a new |
| 364 | +extension should make a note of it there, in order to claim the name. |
| 365 | + |
| 366 | + |
| 367 | +SEE ALSO |
| 368 | +-------- |
| 369 | +linkgit:git-init[1], |
| 370 | +linkgit:git-clone[1], |
| 371 | +linkgit:git-config[1], |
| 372 | +linkgit:git-fetch[1], |
| 373 | +linkgit:git-pack-refs[1], |
| 374 | +linkgit:git-gc[1], |
| 375 | +linkgit:git-checkout[1], |
| 376 | +linkgit:gitglossary[7], |
| 377 | +link:/docs/user-manual[The Git User's Manual] |
| 378 | + |
| 379 | +GIT |
| 380 | +--- |
| 381 | +Part of the linkgit:git[1] suite |
0 commit comments