photo credit: pamlau.com via photopin cc

Create an archive of changed files in your GIT repository

Often I find myself updating my clients’ websites. This can be a simple bugfix or a major update, but eventually I always end up transfering updated files to the FTP-server. Lucky for me, GIT allows me to create a simple archive with only the modified files, making deploying changes to a webserver so much more easy. Here is how it works:
First, get the ID of the commit from which you want the update to ‘start’. From this commit on forward the update will include all changes up to the HEAD of your repository.
Now, open your terminal or Git Bash, go to the root folder of your repository and execute the following command:

Of course you need to replace the ‘[id]’-part with the ID of your commit. So if the ID of your commit is ‘599313e986c56e5451caa14d32c6b18273f4331b’ then your command would look like this:

That’s it! This line will create an archive called ‘update.zip’ which will contain only the files you have modified since the given commit.

Visitors give this article an average rating of 3.6 out of 5.

How would you rate this article?

6 thoughts on “Create an archive of changed files in your GIT repository”

  1. R says:

    The following error occurs when there is a space in a file name.
    “fatal: pathspec ‘ nameafterspace’ did not match any files”

    1. Giel Berkers says:

      Could you show your whole terminal command? Usually this error occurs when there are files in your history that are deleted.

    2. Mr.Pulka says:

      git diff –name-only 3ea2a127 7edc287g > list.txt
      zip archive -@ < list.txt

  2. Bill says:

    very cool! thanks for the post, helped a bunch.

  3. The Z Man says:

    An alternative method if you want to get the changes from one branch to another, say from master to feature, you could do something like:

    git archive -o master-feature.zip HEAD $(git diff –name-only master feature)

  4. manoj says:

    Hi – Thanks for the post.
    When i am giving [id] – latest commit id and that’s last commit in that scenario git diff –name-only [id] not returning any file names.

Leave a Reply