git: Deflating object disk format
git
objects are compressed content of the format <type> <length><nul><content>
.
We can inspect them using git cat-file -t|-p <path>
:
git rev-list --objects --all | head -1
# e02a76e706515fae72f4778cbaa33ec51dc29c24
git cat-file -t e02a76e706
# commit
git cat-file -p e02a76e706
# tree 276dde0dfc1842bbb5f5c650643747897eafc0cf
# parent d9d6be320fcf1295cd3db4b28768ef8dda61f1de
# author Nicholas Edwards <edwardsnjd@googlemail.com> 1692502772 +0800
# committer Nicholas Edwards <edwardsnjd@googlemail.com> 1692502772 +0800
#
# [nb] Add: 20230820113035.md
And we can inspect those using compression utilities directly:
ls .git/objects/e0/2a76e706*
# .git/objects/e0/2a76e706515fae72f4778cbaa33ec51dc29c24
inflate .git/objects/e0/2a76e706515fae72f4778cbaa33ec51dc29c24
# commit 264<NUL>tree 276dde0dfc1842bbb5f5c650643747897eafc0cf
# parent d9d6be320fcf1295cd3db4b28768ef8dda61f1de
# author Nicholas Edwards <edwardsnjd@googlemail.com> 1692502772 +0800
# committer Nicholas Edwards <edwardsnjd@googlemail.com> 1692502772 +0800
#
# [nb] Add: 20230820113035.md
And strip off the header and size to get back to exactly the same as git cat-file -p
:
inflate .git/objects/e0/2a76e706515fae72f4778cbaa33ec51dc29c24 | tr '\0' '¶' | sed 's/.*¶//'
# tree 276dde0dfc1842bbb5f5c650643747897eafc0cf
# parent d9d6be320fcf1295cd3db4b28768ef8dda61f1de
# author Nicholas Edwards <edwardsnjd@googlemail.com> 1692502772 +0800
# committer Nicholas Edwards <edwardsnjd@googlemail.com> 1692502772 +0800
#
# [nb] Add: 20230820113035.md
Published on: 20 Aug 2023