Skip to content

Instantly share code, notes, and snippets.

Created Apr 17, 2019
What would you like to do?
Zip latest committed changes only

git archive will accept paths as arguments. All you should need to do is:

git archive -o ../ some-commit $(git diff --name-only earlier-commit some-commit)

or if you have files with spaces (or other special characters) in them, use xargs:

git diff --name-only earlier-commit some-commit | xargs -d'\n' git archive -o ../ some-commit

If you don't have xargs properly installed, you could cook up an alternative:


files=($(git diff --name-only earlier-commit some-commit))

git archive -o ../ some-commit "${files[@]}"

Written as a shell script, but should work as a one-liner too. Alternatively, change earlier-commit, some-commit, and ../ to $1 $2 and $3 and you've got yourself a reusable script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment