Skip to content

Instantly share code, notes, and snippets.

@janglapuk
Last active November 27, 2023 10:34
Show Gist options
  • Select an option

  • Save janglapuk/2e84fbc6faa5dda486ecdb2f45fccc23 to your computer and use it in GitHub Desktop.

Select an option

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
# 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 -r archive.zip vendor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment