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

后端 未结 3 613
后悔当初
后悔当初 2021-01-06 17:21

Keeping the file structure, like git-archive

3条回答
  •  庸人自扰
    2021-01-06 18:04

    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.

提交回复
热议问题