Skip to content

Instantly share code, notes, and snippets.

@betweenbrain
Created April 2, 2012 14:56
Show Gist options
  • Star 54 You must be signed in to star a gist
  • Fork 13 You must be signed in to fork a gist
  • Save betweenbrain/2284129 to your computer and use it in GitHub Desktop.
Save betweenbrain/2284129 to your computer and use it in GitHub Desktop.
Git command to export only changed files between two commits
git archive --output=file.zip HEAD $(git diff --name-only SHA1 SHA2)
@Mart-Bogdan
Copy link

It's failing if any file contain spaces in it's name.

Do you have any ideas how to fix this?

@viperet
Copy link

viperet commented Nov 16, 2015

@Mart-Bogdan, try this:
git diff --name-only -z --diff-filter=ACMRT release..HEAD | xargs -0 git archive -o update.tar.gz HEAD --

archives changes between commit tagged release and HEAD. Works with files containing spaces.

@borgle
Copy link

borgle commented Jul 11, 2016

git diff --name-only SHA1..SHA2 | xargs tar -zcf update.tar.gz

or

tar -zcf update.tar.gz git diff --name-only SHA1..SHA2

@nebadom
Copy link

nebadom commented Jun 19, 2017

For some weird reason, when I try tar -zcf (attempting to generate a gzipped version) it just doesn't save all the affected files. However, if I use tar -rf it does work as intended.

Any idea why that is ocurring?

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