目录搜索
GuidesgitattributesgiteverydaygitglossarygitignoregitmodulesgitrevisionsgittutorialgitworkflowsAdministrationgit archivegit bundlegit cleangit filter-branchgit fsckgit gcgit instawebgit reflogBasic Snapshottinggit addgit commitgit diffgit mvgit resetgit rmgit statusBranching and Merginggit branchgit checkoutgit loggit mergegit mergetoolgit stashgit tagDebugginggit bisectgit blamegit grepEmailgit amgit format-patchgit request-pullgit send-emailExternal Systemsgit fast-importgit svnGetting and Creating Projectsgit clonegit initGitgit annotategit archimportgit bisect-lk2009git check-attrgit check-mailmapgit check-ref-formatgit checkout-indexgit cherrygit citoolgit columngit credentialgit credential-cachegit credential-storegit cvsexportcommitgit cvsimportgit cvsservergit diff-filesgit diff-treegit difftoolgit fast-exportgit fetch-packgit fmt-merge-msggit get-tar-commit-idgit guigit http-backendgit http-fetchgit http-pushgit imap-sendgit index-packgit interpret-trailersgit ls-remotegit ls-treegit mailinfogit mailsplitgit merge-filegit merge-indexgit merge-one-filegit merge-treegit mktaggit mktreegit name-revgit notesgit p4git pack-objectsgit pack-redundantgit pack-refsgit parse-remotegit patch-idgit prunegit prune-packedgit quiltimportgit receive-packgit remote-extgit remote-fdgit remote-testgitgit repackgit replacegit rereregit send-packgit sh-i18ngit sh-setupgit shellgit show-branchgit show-indexgit stripspacegit unpack-filegit unpack-objectsgit upload-archivegit upload-packgit vargit verify-commitgit verify-taggit whatchangedgit worktreeInspection and Comparisongit describegit shortloggit showMiscellaneousapi credentialsapi indexgitcligitcore tutorialgitcredentialsgitcvs migrationgitdiffcoregithooksgitkgitnamespacesgitremote helpersgitrepository layoutgitsubmodulesgittutorial 2gitwebgitweb.confpack formatUser ManualPatchinggit applygit cherry-pickgit rebasegit revertPlumbing Commandsgit cat-filegit check-ignoregit commit-treegit count-objectsgit diff-indexgit for-each-refgit hash-objectgit ls-filesgit merge-basegit read-treegit rev-listgit rev-parsegit show-refgit symbolic-refgit update-indexgit update-refgit verify-packgit write-treeServer Admingit daemongit update-server-infoSetup and Configgitgit configgit helpSharing and Updating Projectsgit fetchgit pullgit pushgit remotegit submodule
文字

Pack-*.pack 文件具有以下格式:

  • 标题出现在开头,包含以下内容:4字节签名:签名是:{'P','A','C','K'}

  4-byte version number (network byte order): Git currently accepts version number 2 or 3 but        generates version 2 only.

包中包含4个字节的对象数(网络字节顺序)

观察:我们不能超过 4G 版本;-)和一个包中超过 4G 的对象。

  • 头部后面跟着一些对象条目,每条对象条目如下所示:(未分割表示)n 字节类型和长度(3位类型,(n-1)* 7 + 4位长度)压缩数据

  (deltified representation)    n-byte type and length (3-bit type, (n-1)\*7+4-bit length)    20-byte base object name if OBJ\_REF\_DELTA or a negative relative offset from the delta object's position in the pack if this is an OBJ\_OFS\_DELTA object    compressed delta data

观察:每个对象的长度都是以可变长度格式编码的,并不限于32位或任何其他内容。

  • 预告片记录了上述所有内容的20字节 SHA-1 校验之和。

原始(版本1)pack-*.idx 文件具有以下格式:

  • 标题由256个4字节的网络字节顺序整数组成。此表的第 N 个条目记录对应包中对象的数量,其对象名称的第一个字节小于或等于 N 。这称为first-level fan-out表格。

  • 标题后面是已排序的24字节条目,每个对象包含一个条目。每个条目是:4字节的网络字节顺序整数,记录对象存储在 packfile 中的位置,作为从开始的偏移量。

20字节的对象名称。

  • 该文件以一个结尾结束:在相应的包文件末尾的20字节SHA-1校验和的副本。

上述所有的20字节 SHA-1 校验和。

包 Idx 文件:

        --  +--------------------------------+fanout            | fanout[0] = 2 (for example)    |-.table            +--------------------------------+ |            | fanout[1]                      | |            +--------------------------------+ |            | fanout[2]                      | |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |            | fanout[255] = total objects    |---.        --  +--------------------------------+ | |main            | offset                         | | |index            | object name 00XXXXXXXXXXXXXXXX | | |table            +--------------------------------+ | |            | offset                         | | |            | object name 00XXXXXXXXXXXXXXXX | | |            +--------------------------------+<+ |          .-| offset                         |   |          | | object name 01XXXXXXXXXXXXXXXX |   |          | +--------------------------------+   |          | | offset                         |   |          | | object name 01XXXXXXXXXXXXXXXX |   |          | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   |          | | offset                         |   |          | | object name FFXXXXXXXXXXXXXXXX |   |        --| +--------------------------------+<--+trailer          | | packfile checksum              |          | +--------------------------------+          | | idxfile checksum               |          | +--------------------------------+          .-------.                  |Pack file entry: <+
    packed object header:1-byte size extension bit (MSB)       type (next 3 bit)       size0 (lower 4-bit)
       n-byte sizeN (as long as MSB is set, each 7-bit)
        size0..sizeN form 4+7+7+..+7 bit integer, size0
        is the least significant part, and sizeN is the
        most significant part.
    packed object data:
       If it is not DELTA, then deflated bytes (the size above
        is the size before compression).If it is REF_DELTA, then  20-byte base object name SHA-1 (the size above is the
        size of the delta data that follows).
         delta data, deflated.If it is OFS_DELTA, then
  n-byte offset (see below) interpreted as a negative
        offset from the type-byte of the header of the
        ofs-delta entry (the size above is the size of
        the delta data that follows).
  delta data, deflated.
  offset encoding:n bytes with MSB set in all but the last one.The offset is then the number constructed by
concatenating the lower 7 bit of each byte, andfor n >= 2 adding 2^7 + 2^14 + ... + 2^(7*(n-1))to the result.

版本2 pack-*.idx 文件支持包大于4 gib ,并且

have some other reorganizations.  They have the format:
  • 一个4字节的幻数\377tOc,这是一个不合理的扇出值。

  • 一个4字节的版本号(= 2)

  • 与 v1 一样,256个扇出扇出表。

  • 一个已排序的20字节 SHA-1 对象名称表。它们被打包在一起而没有偏移值,以减少特定对象名称的二进制搜索的高速缓存占用空间。

  • 打包对象数据的4字节 CRC 32值表。这是 v2 中的新功能,因此压缩数据可以在重新打包时直接从包中复制,而不会发生未检测到的数据损坏。

  • 一个4字节的偏移量值表(按照网络字节顺序)。这些通常是31位的打包文件偏移量,但大偏移量被编码为下一个带有 msbit 集的表中的索引。

  • 一个8字节的偏移量表(对于小于2 GiB 的包文件为空)。包文件使用大量使用的对象组织,因此大多数对象引用不需要引用此表。

  • 与 v1 包文件相同的尾部:对应包文件末尾的20字节 SHA-1 校验和副本。

上述所有的20字节 SHA-1 校验和。

上一篇:下一篇: