Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting / Archiving changed files only in Git

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'? 
like image 293
AKS Avatar asked Nov 05 '09 02:11

AKS


People also ask

What is git diff tree?

git-diff-tree - Compares the content and mode of blobs found via two tree objects.

How do I export a file from Git?

Step 1: Go to your git bash. and then to the repo you want to extract or export. Here, we are going to export this repo named 'Ada August-a Challenge' and it's main branch. Step 2: Now export it to your preferred format and location, here we will export it to the same location in .

What is git archive command?

git archive --format=tar HEAD. This command when executed will create an archive from the current HEAD ref of the repository. By default, git archive will stream the archive output to the ephemeral stdout stream. You will need to capture this output stream to a permanent file.


1 Answers

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.

like image 107
Greg Hewgill Avatar answered Sep 25 '22 02:09

Greg Hewgill