Question

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'm new to Linux/Git).

I am using msysgit, and for the most part I'm fine with deploying entire repositories but in many cases it is much more efficient to deploy small fixes a few files at a time.

Pushing/pulling/installing git on the remote servers isn't really an option as my level of access varies between projects and clients.

Is there a straight-forward way to (rough guess):

pipe 'diff --names-only' to 'git-archive'? 
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top