Wulf's Webden

The Webden on WordPress

Undo

Being able to undo a mistake is one of the features that can greatly improve a computer interface and even better when it can let you travel an arbitrary number of steps back in time. Today I have been brushing up on how to do that with the Git version control system.

One of my safety nets for database systems is to take a daily dump of the contents and then automatically add this to a repository. Since Git is very good at handling text files and most databases don’t have that many changes each day (especially when they shift from active data entry to coasting along) it is more efficient than storing large numbers of individually named back up files. I haven’t yet need to to roll back in earnest but I decided it was about time I figured out what to do when the need arises.

It turns out that I simply need to use two commands. The first is git log, which lets me find a identifier for a given commit. The second is git show — by passing it a reference in the form of commit-id:filename (note the colon separating the two) I can see the contents of the file at the specified commit and I can also use > to redirect it to a given file (if, for example, I want to compare the old version to the current version).

Oodles of undo… lovely!

Comments are closed.