gitgit-archive

Git archive without first/initial commit


How to make tar archive from git repository since selected commit?

This question is similar to Git archive all changes except first commit but I need .tar archive as a result not git patch file.

Explanation: I make "modules" for a strange PHP CMS where there is no real mechanism for writing extensions. To ship my modules I have to send only the modified files to clients, while I still have to have all CMS files under Git (all added only in first commit).


Solution

  • So, the recipient of this archive doesn't have the repo but does have the content of some commit, and you're sending replacements he can untar onto that?

    It seems git archive's --output option on windows fails at telling the compressor about the redirection, which duly refuses to write compressed output to what it thinks is a terminal, but that's easily worked around:

    git archive -o update-old-new.tgz newcommit \
             $(git diff --name-only --diff-filter=AM oldcommit..newcommit) | cat
    

    That | cat at the end is the workaround.

    I'd forgotten about archive, but using it means you don't have to checkout $newcommit first so this is much better than the earlier checkout;diff|tar combo.

    Still, this can't handle an update large enough to blow command-line limits, or spaces or other annoying characters in the pathnames. The fallback is

    git checkout newversion
    git diff --name-only --diff-filter=AM oldversion.. \
    | tar Tczf - update-old-new.tgz