[ #71 ] Using Git to Rollback Bad Deployments Permalink

Git, ThisBlog, Apache Added a year and a bit ago and last edited a year and a bit ago

Git just keeps rocking my world.

OK, here is how I deploy my blog and here is how git saved me last night when the deployment went bad:

I git-pull into a webroot directory (well, the directory that is setup to serve my python) from my main git repo (which is also hosted on the same machine.)

When I updated the blog software last night I did a git-pull, restarted apache and saw the error (yes I should've caught it in dev, shoulda-coulda-woulda but-but-but.)

So, error noted. What do I do to rollback to the last working version?

$ git log

... and I copy the SHA hex-string of the last working commit. Then we rollback with:

$ git checkout <copied_hex_string>

... and restart apache. Ta-da! Now the blog is still up while I do the bug fix.

OK so what happens when I've commited the fix and I want to make the blog update?

$ git pull

... puts all the new changes in the git repo but doesn't fast-forward it to the HEAD of master automatically. Why? Because you aren't in master anymore - you've checked out a previous commit. So all you need to do now is:

$ git checkout master

... restart apache and you're set.

EDIT: Here is some info to rollback to the previous commit in a more general way:

$ git checkout HEAD~1
...  # you are now at the previous version
$ git checkout master
... # you are now back to the latest version

Colophon

Django Python 960.gs Git Vim NetBSD Nginx

The Author

This is the blog of Brad Willis, a software engineer living in Brisbane.

Meta

Help
Latest entries

*BSD Agile Apache Apple apt Athletics Best-Practice Censorship Comedy Cool Crosswords Deployment Django English Exim Firefox Git Hardcore Health irssi Javascript Jira Languages Linux Makefile Mathematics Mobile Broadband Mutt MySQL NetBSD nginx Nokia OpenVZ OSX Perl Privacy Python Rant Requirements rsync Ruby Shell Slackware SQL SQLite SSH Standards Subversion Television Testing ThisBlog Vim VMWare (Fusion) VPN X zsh

Recent Entries

Checking for exceptions in doctests
Homer's Curling Speech
retry in Python
Vim Makefile tabs
Centos (or RH) IPTables
Converting ssh2 public keys to openssh
Vim comment hints
Context managers in Perl
Dish rotation
Git - fixing commit user
apt stuff
Using shell variables in AWK
Linux - Too many open files
Tell gvim to save and quit... remotely
Vim - automatically remove whitespace at EOL
Python - relative paths from within modules
TV Aspect Ratios
Git - Which commits are in your branch only?
Subversion setup cheat sheet
Force detach a screen session
Modify sudo's use of environment variables
Install all Perl modules
Mutt - delete old messages
OpenVZ VPS and swap space
fail2ban on NetBSD for ssh
NetBSD - Using sup
Python - testing for a sys.exit
Python Best Practice Link Dump
Python script names
Perl - Using an expensive module
Speed of git clone
Perl Modules with Custom Prefix
Perl: tr vs. s
Brilliant sysadmin Reference
Why is GRUB better than LILO?
Why is swap space important?
Perldoc Output
Git's Index
Jira Project Keys
Git GUI

Links

ChoppingBoard, DaveMisc, Project365, RageQuit