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.

Recent posts View all

Talk CSS

FrontEnders - Web Performance

Sharing some of my thoughts on a FrontEnders meetup on the topic of Web Performance

Conferences

Tips for how to ask for time off to attend conferences

Asking for time off to attend a conference can be nerve-racking, these tips will get you closer to attending the conferences you're interested in.