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:
1 |
git archive -o update.zip HEAD $(git diff --name-only [id]) |
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:
1 |
git archive -o update.zip HEAD $(git diff --name-only 599313e986c56e5451caa14d32c6b18273f4331b) |
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?
★ ★ ★ ★ ★
The following error occurs when there is a space in a file name.
“fatal: pathspec ‘ nameafterspace’ did not match any files”
Could you show your whole terminal command? Usually this error occurs when there are files in your history that are deleted.
git diff –name-only 3ea2a127 7edc287g > list.txt
zip archive -@ < list.txt
very cool! thanks for the post, helped a bunch.
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)
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.