开发者

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

开发者 https://www.devze.com 2023-03-31 22:40 出处:网络
Keeping the fil开发者_如何学Goe structure, like git-archivegit archive takes file paths as arguments, so you could do something like:

Keeping the fil开发者_如何学Goe structure, like git-archive


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.


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 --


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号