Due formati, due scopi
git archive produce uno snapshot tar o zip di un tree — codice senza storia, perfetto per i rilasci. git bundle produce un file di trasporto portatile contenente oggetti e ref — perfetto per il trasferimento offline di un intero repo.
Esempi archive
git archive --format=tar.gz -o release-1.0.tar.gz v1.0.0
git archive --format=zip --prefix=myapp-1.0/ -o myapp-1.0.zip HEAD
git archive --format=tar HEAD src/ | tar -xC /tmp/snapshot
Escludere file dagli archive
tests/ export-ignore
.github/ export-ignore
*.dev.json export-ignore
Bundle per trasferimento offline
git bundle create repo.bundle --all
git bundle create incr.bundle main ^origin/main
git bundle verify repo.bundle
git clone repo.bundle myrepo
git fetch repo.bundle main:imported
Caso d'uso: spedire a un cliente embargoed
git bundle create v1.2.bundle main --tags
git fetch v1.2.bundle '+refs/heads/*:refs/remotes/upstream/*' '+refs/tags/*:refs/tags/*'
Archive riproducibili
git archive --format=tar.gz \
--output=src.tar.gz \
--prefix=src/ HEAD
Errori comuni
Confondere git archive (no storia) con git bundle (storia completa). Dimenticare --prefix producendo una "tarbomb".