Git Pie: A Arte Ancestral do Versionamento 🥧 Help

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

SHA-1

Primeiros 2 chars

Restante

Conteúdo

Hash

Diretório

Nome do Arquivo

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

Aponta para

Tree

Blob

Tree

Blob

Tag

Commit

Root Tree

arquivo1.txt

diretório

arquivo2.txt

Integridade dos Objetos

Garantias do Sistema

IntegridadeHash SHA-1ImutávelVerificávelÚnicoDeterminísticoRead-onlyContent-addressedChecksumChain

Compressão e Performance

Estratégias de Otimização

  1. Zlib compression

  2. Delta encoding

  3. Packfiles

  4. 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

  1. Evite arquivos grandes

  2. Use Git LFS quando necessário

  3. Execute gc regularmente

  4. Monitore o tamanho do repositório

Troubleshooting

Problemas Comuns

ProblemasCorrupçãoPerformanceEspaçoVerificarRepararCompactarOtimizarLimparComprimir

Próximos Passos

Tópicos Relacionados

22 abril 2025