Skip to content

Instantly share code, notes, and snippets.

@janglapuk
Last active November 27, 2023 10:34
Show Gist options
  • Save janglapuk/2e84fbc6faa5dda486ecdb2f45fccc23 to your computer and use it in GitHub Desktop.
Save janglapuk/2e84fbc6faa5dda486ecdb2f45fccc23 to your computer and use it in GitHub Desktop.
Git archive cheatsheet

Archive HEAD

git archive --output=archive.zip HEAD

Archive HEAD with directory prefix (like github ZIP archive)

git archive --output=archive.zip --prefix=main/ HEAD

Important: prefix should have a trailing slash

Archive changes between two commits (bash)

git archive --output=archive.zip HEAD $(git diff --name-only commit_ID_A commit_ID_B)

Archive changes between two commits (PowerShell)

git diff --name-only commit_ID_A commit_ID_B | Out-File -Encoding ASCII changes.txt
git archive --output=archive.zip HEAD -- $(Get-Content changes.txt)

Archive HEAD with excluded file/directory from .gitignore (e.g. .env, vendor, node_modules, etc.)

git archive --output=archive.zip HEAD
7z a archive.zip vendor

If --prefix is set, then you need to rename (7z rn) the directory to place inside prefix directory

git archive --output=archive.zip --prefix=main/ HEAD
7z a archive.zip vendor
7z rn archive.zip vendor main/vendor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment