Skip to content

Zip files in a range of commits

Michael Watts edited this page Apr 29, 2019 · 1 revision

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.

Source: https://stackoverflow.com/questions/3423540/zip-latest-committed-changes-only

SSH

2 Best practices when logging in remotely to linux machine

WARGAMES

Clone this wiki locally