Ildar
Ildar

Reputation: 796

Git. How to create archive with files, that have been changed?

Keeping the file structure, like git-archive

Upvotes: 3

Views: 2221

Answers (3)

Hatjhie
Hatjhie

Reputation: 1365

Courtesy of @Charles Duffy https://stackoverflow.com/users/14122/charles-duffy

Thanks to @Viperet answer. Below is to insert a pause if you have a very long list files to be archived. Xargs will run the same command multiple time with split arguments hence it will always produce the archived zip with the last split arguments. To correct that, a quick workaround is to insert a pause in between.

Again, it's a courtesy from Charles Duffy. XARGS Long Arguments and Pause Between Commands

Updated command:

git diff --name-only -z --diff-filter=ACMRT release..HEAD | xargs -0 bash -c '"$@"; sleep 10' _ git archive -o update.tar.gz HEAD

Hope it helps others as well.

Thank you,

Hatjhie

Upvotes: 0

Viperet
Viperet

Reputation: 1434

Here is command to archive changes between commit tagged release and HEAD, also works with filenames that includes spaces, quotes, double quotes, any special characters:

git diff --name-only -z --diff-filter=ACMRT release..HEAD | xargs -0 git archive -o update.tar.gz HEAD --

Upvotes: 2

Chaitanya Gupta
Chaitanya Gupta

Reputation: 4053

git archive takes file paths as arguments, so you could do something like:

git diff --name-status commit1 commit2 | awk '{ if ($1 != "D") print $2 }' | xargs git archive -o output.zip HEAD

UPDATE

The following will work if your file names include spaces:

git diff --name-status commit1 commit2 | awk '{ if ($1 != "D") printf("\"%s\"\n", substr($0,3)) }' | xargs git archive -o output.zip HEAD --

Note: the content of the files included in the archive is what it is at HEAD. To use content from some other commit, just change HEAD at the end of this command to whatever you want it to be.

Upvotes: 3

Related Questions