Objetos Git: Os Blocos Fundamentais
+------------------+
| Git Object |
| Database |
| |
| SHA-1 -> Data |
| |
| Type + Size |
| + Content |
+------------------+
Tipos de Objetos
1. Blob (Binary Large Object)
+-------------+
| BLOB |
+-------------+
| • Conteúdo |
| • SHA-1 |
| • Tamanho |
+-------------+
Exemplo de estrutura interna:
blob 42\0Hello, World!
2. Tree (Árvore)
+----------------+
| TREE |
+----------------+
| 100644 blob K1|
| 100755 blob K2|
| 040000 tree K3|
+----------------+
Exemplo de estrutura:
$ git cat-file -p master^{tree}
100644 blob a906cb2a4a904... README.md
100644 blob 8ab686eafeb5... index.js
040000 tree ab8763f6e1dd... src
3. Commit
+------------------+
| COMMIT |
+------------------+
| • Tree |
| • Parent(s) |
| • Author |
| • Committer |
| • Message |
+------------------+
Exemplo de estrutura:
tree a906cb2a4a904...
parent 83bc0145a898...
author Dev <dev@example.com> 1625097600 -0300
committer Dev <dev@example.com> 1625097600 -0300
Initial commit
4. Tag
+------------------+
| TAG |
+------------------+
| • Object |
| • Type |
| • Tag Name |
| • Tagger |
| • Message |
+------------------+
Como os Objetos São Armazenados
Estrutura do Diretório
.git/objects/
├── pack/
│ ├── pack-*.pack
│ └── pack-*.idx
├── info/
└── xx/
└── yyyyyyyyyy...
Processo de Hash
Manipulando Objetos
Comandos Essenciais
# Criar blob
echo 'test content' | git hash-object -w --stdin
# Ver conteúdo
git cat-file -p <hash>
# Ver tipo
git cat-file -t <hash>
# Ver tamanho
git cat-file -s <hash>
Relacionamentos Entre Objetos
Integridade dos Objetos
Garantias do Sistema
Compressão e Performance
Estratégias de Otimização
Zlib compression
Delta encoding
Packfiles
Garbage collection
Exemplo de Delta
Base object: "Hello World"
Delta: @@ -1,5 +1,6 @@
Hello
+New
World
Dicas Práticas
Debug e Inspeção
# Listar todos objetos
git rev-list --objects --all
# Encontrar objetos grandes
git verify-pack -v .git/objects/pack/*.idx
# Inspecionar packfile
git unpack-objects -n < .git/objects/pack/*.pack
Boas Práticas
Evite arquivos grandes
Use Git LFS quando necessário
Execute gc regularmente
Monitore o tamanho do repositório
Troubleshooting
Problemas Comuns
Próximos Passos
Tópicos Relacionados
22 abril 2025