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

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

Keeping the file structure, like git-archive

相关标签:
3条回答
  • 2021-01-06 17:49

    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 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-06 18:06

    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 --
    
    0 讨论(0)
提交回复
热议问题