Git has the very handy archive command which allows me to make a copy of a particular commit in a .zip archive like so:
git archive -o ../latest.zip some-commit
This will contain the entire working tree for that commit. Usually I just need the changed files since a previous release. Currently I use this to get those files into a zip:
git diff --name-only previous-commit latest-commit | zip ../changes.zip -@
This will however zip files from my working copy, which may have uncommitted changes. Is there some way to get only the changed files as they were committed directly into a zip?
git archivewill accept paths as arguments. All you should need to do is:or if you have files with spaces (or other special characters) in them, use xargs:
If you don’t have xargs properly installed, you could cook up an alternative:
Written as a shell script, but should work as a one-liner too. Alternatively, change
earlier-commit,some-commit, and../latest.zipto$1$2and$3and you’ve got yourself a reusable script.