Sarke February 2016

Make files in web server match a certain git commit

I am trying to set up my web server to download a particular version of the website. Basically all I need on the server is to be able to issue a command that will make the folder match that commit.

I've tried searching for this, but it seems there is LOTS of info on git, and many different answers. So I'm not sure what the answer is, or what the CORRECT answer is.

This is what I find to work, but it's seems a bit convoluted.

git fetch origin
git checkout {hash}
git pull

Is there a better way? And will this work in all situations (state of repo, etc)?

To clarify I don't need to make any commits on the web server, it only needs to receive.

Answers


poke February 2016

You can use git reset --hard to put your working directory into the exact state of a commit. I generally do the following on server when deploying a version (usually automated):

git fetch origin
git reset --hard origin/master

This will overwrite all tracked files with the version from the just fetched origin/master.

Note that this does not remove untracked or ignored files. If you need to do that, you need to run git clean afterwards:

git clean -xdf

Post Status

Asked in February 2016
Viewed 2,639 times
Voted 7
Answered 1 times

Search




Leave an answer