Skip to content

Instantly share code, notes, and snippets.

@eduwass
Created April 17, 2019 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eduwass/ed29539c0dd2b38327e793ad38dc64fb to your computer and use it in GitHub Desktop.
Save eduwass/ed29539c0dd2b38327e793ad38dc64fb to your computer and use it in GitHub Desktop.
Zip latest committed changes only

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

git archive -o ../latest.zip 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 ../latest.zip some-commit

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

#!/bin/bash

IFS=$'\n'
files=($(git diff --name-only earlier-commit some-commit))

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

Written as a shell script, but should work as a one-liner too. Alternatively, change earlier-commit, some-commit, and ../latest.zip 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