views:

140

answers:

2

I'm using Git for version control and unlike SVN I have not come across an inherent means of performing an export of changed files between 2 revisions, branches or tags.

As an alternative I want to use the linux zip command and pass it a set of file names, however the file names are the result of another command git diff. Below is an example of what I am trying to achieve:

zip /home/myhome/releases/files.zip git diff --name-only -a 01-tag 00-tag

However the above does not work as I guess the 'zip' command sees the git operation as part of its command options.

Does someone know how I can make something like the above work?

Thanks

+2  A: 

You need to execute the git command in a sub-shell:

zip /home/myhome/releases/files.zip `git diff --name-only -a 01-tag 00-tag`
# another syntax (assuming bash):
zip /home/myhome/releases/files.zip $(git diff --name-only -a 01-tag 00-tag)

Another option is the xargs command:

git diff --name-only -a 01-tag 00-tag | xargs zip /home/myhome/releases/files.zip
soulmerge
It's more accurate to say you need to execute the git command via `command substitution`. Command substitution uses a sub-shell, but a sub-shell is a more general concept used in other ways as well (see http://tldp.org/LDP/abs/html/subshells.html#SUBSHELLSREF)
R Samuel Klatchko
Thanks for this, worked like a charm! :)
Newbie
@R Samuel Klatchko: thx for the link, didn't know that
soulmerge
A: 

If you're in a git shell (bash) you can also do this:

git diff -–name-only commit1 commit2 | zip ../Changes.zip –@

Works for me on Windows and Unix based systems.

Marnix van Valen