Using Git to create an archive of changed files.

Often I have found myself in a situation where it would be really nice to have an archive of the files I have recently been working on.

Using two Git commands I can easily create such an archive.

The first actually creates the archive;

git archive -o update.zip HEAD

This will create an archive of the entire repository, which isn't what we want in this instance but is pretty handy to know.

The archive function accepts a list of files to archive, which is what we want to do and is where our second command comes in.

git diff --name-only HEAD^

This will do the commit before the head, which is what I want most of the time but this could be changed to get files between two commits or anything you wanted, check out the help section in git for the diff command.

Finally we want to bring this all together into one nice and easy command, thus;

git archive -o update.zip HEAD $(git diff --name-only HEAD^)

This wraps our second command with $(), this gets ran first and passes the result as a parameter into our first command.