Git Pie: A Arte Ancestral do Versionamento 🥧 Help

Git Internals: Como o Git Funciona por Dentro

+------------------------+ | Git Object | | Storage | | | | +---------------+ | | | Commit | | | | +-Tree-+ | | | | |Blob | | | | | |Blob | | | | | +------+ | | | +---------------+ | | | | .git/ | | ├── objects/ | | ├── refs/ | | └── HEAD | +------------------------+

Sistema de Objetos do Git

Tipos de Objetos

Objetos GitBlobTreeCommitTagConteúdoSHA-1DiretóriosPermissõesMetadadosSnapshotAnotadaLeve

Como os Objetos se Relacionam

Aponta para

Contém

Subdiretório

Arquivo

Parent

Commit

Tree

Blob

Tree

Blob

Commit Anterior

Anatomia de um Commit

Estrutura Básica

commit 1fc408bfdb92... tree a906cb2a4a904... parent 83bc0145a898... author Stifler <stifler@milfsgo.com> 1625097600 -0300 committer Stifler <stifler@milfsgo.com> 1625097600 -0300 feat: adiciona sistema de busca de milfs

Composição do SHA-1

Hash

Hash

Hash

Metadata

SHA-1

Content

Parent

Sistema de Referências

Referencias Principais

RefsHEADBranchTagRemoteCurrentDetachedLocalRemoteLightweightAnnotatedOriginUpstream

Como o HEAD Funciona

Aponta para

Aponta para

Detached

HEAD

Branch

Commit

Armazenamento de Objetos

Estrutura do .git

.git/ ├── objects/ │ ├── pack/ │ ├── info/ │ ├── aa/ │ └── bb/ ├── refs/ │ ├── heads/ │ ├── tags/ │ └── remotes/ ├── HEAD └── config

Processo de Compressão

git gc

Delta

Objetos Soltos

Packfile

Comprimido

Como o Git Armazena Mudanças

Snapshot vs Delta

Git

Snapshot 1

Snapshot 2

Snapshot 3

Outros VCS

Delta

Delta

V1

V2

V3

Processo de Staging

RepositoryStagingWorking DirRepositoryStagingWorking DirCria objetosCria commitgit addgit commit

Garbage Collection

O que é Coletado

  • Objetos não referenciados

  • Objetos soltos antigos

  • Referências dangling

  • Packfiles redundantes

Quando Acontece

git gc

Threshold

Server

Manual

GC

Auto

Push

Dicas de Performance

Otimizações

  1. Clones rasos

  2. Sparse checkout

  3. Partial clone

  4. Prune regular

Monitoramento

Size

Health

Optimize

git count-objects

Disk Usage

git fsck

Repository

git gc --aggressive

Performance

Comandos para Exploração

Comandos Úteis

# Ver objeto git cat-file -p SHA1 # Listar referências git show-ref # Ver árvore git ls-tree HEAD # Contar objetos git count-objects -v # Verificar integridade git fsck

Considerações de Segurança

Proteção de Dados

SegurançaHashRefsObjectsSHA-1CollisionProtectedSignedImmutableVerified

Próximos Passos

Tópicos Avançados

22 abril 2025