Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Roll back git repository with deployment hook

Tags:

git

deployment

I have a bare git repository set up on a production server, and it uses a post receive hook to deploy whatever I push there:

#!/bin/sh
GIT_WORK_TREE=/path/to/webroot git checkout -f

To deploy I do

git push production

From my work station, and everything is taken care of. But say I push a commit that breaks something and I want to revert asap. Will doing the following work:

git push production [id of commit to revert to]:master

IE will this still deploy everything in to the webroot correctly?

like image 534
Cameron Ball Avatar asked Oct 24 '25 18:10

Cameron Ball


1 Answers

That should work as expected. You probably need to do git push +<commit>:master (note the +) in order to replace the bad commit at the HEAD of production master.

+<commit>:master is a refspec, see the git push manpage for more information about refspecs.

I would recommend reverting more explicitly without needing to force push to the production server by doing:

git revert <commit to revert>
git push production

or

git reset --hard <commit to revert to>
git push -f production

See How to revert Git repository to a previous commit?

like image 61
mwhite Avatar answered Oct 26 '25 08:10

mwhite



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!