Exporting / Archiving changed files only in Git

后端 未结 1 1074
庸人自扰
庸人自扰 2020-12-07 23:27

Is there a simple way to export / archive only the changed files from a given commit or series of commits in git? I can\'t seem to find clear instructions to do this (and I\

相关标签:
1条回答
  • 2020-12-08 00:33

    I don't think there's any need to involve git-archive. Using --name-only, you could tar up the files:

    tar czf new-files.tar.gz `git diff --name-only [diff options]`
    

    Since you're new to Linux, this might need some explanation:

    The backticks in the command line cause the shell to first execute the command within the backticks, then substitute the output of that command into the command line of tar. So the git diff is run first, which generates a list of filenames, one on each line. The newlines are collapsed to spaces and the whole list of files is placed on the tar command line. Then tar is run to create the given archive. Note that this can generate quite long command lines, so if you have a very large number of changed files you may need a different technique.

    0 讨论(0)
提交回复
热议问题