Git Internals

https://book.git-scm.com/book/en/v2/Git-Internals-Git-Objects

Plumbing commands #

Put object into the git db #

$ echo 'test content' | git hash-object -w --stdin
d670460b4b4aece5915caf5c68d12f560a9fe3e4
  • -w means actually write it in
  • --stdin required (otherwise the git hash-object command expects filename as 2nd arg)

The key returned is the SHA-1 key used to reference things in the .git/objects/ folder. This hash is 40-characters long with a header (2 chars) and payload (38 chars).

Find all internal git objects #

$ find .git/objects -type f
.git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4

Pretty-print file content #

$ git cat-file -p d670460b4b4aece5915caf5c68d12f560a9fe3e4
test content

Get type of object #

$ git cat-file -t 1f7a7a472abf3dd9643fd615f6da379c4acb3e3a
blob

July 17, 2020
tags: git, sha-1