Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you pass a file list to the linux zip command

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

like image 838
newbie Avatar asked Apr 10 '10 17:04

newbie


People also ask

How do I zip a list of files in UNIX?

Syntax : $zip –m filename.zip file.txt 4. -r Option: To zip a directory recursively, use the -r option with the zip command and it will recursively zips the files in a directory. This option helps you to zip all the files present in the specified directory.

How do you zip files in Linux?

Using the zip command, create a ZIP archive of the newly created files. To create a ZIP archive, we simply use the command zip followed by the name we are giving the archive and then a list of the files we wish to include in the archive.

How do I zip a group of files in Linux?

The Unix ZIP Command To create a ZIP file, go to the command line and type "zip" followed by the name of the ZIP file you want to create and a list of files to include. For example, you could type "zip example. zip folder1/file1 file2 folder2/file3" to create a ZIP file called "example.

How do I zip an entire directory in Linux?

You can compress directories and the corresponding sub-directories by using the -r flag. The -r flag will tell zip to traverse the entire directory recursively. To suppress the output from the compression process, use the -q for quiet mode. The command creates a zip archive of the specified files with no output.


1 Answers

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
like image 163
soulmerge Avatar answered Oct 16 '22 09:10

soulmerge