Chapter 9. Finding and Fixing Mistakes
To err might be human, but to really handle the consequences well takes a top-notch revision control system. In this chapter, we’ll discuss some of the techniques you can use when you find that a problem has crept into your project. Mercurial has some highly capable features that will help you to isolate the sources of problems, and to handle them appropriately.
Erasing Local History
The Accidental Commit
I have an occasional but persistent problem of typing rather more quickly than I can think, which sometimes results in me committing a changeset that is either incomplete or plain wrong. In my case, the usual kind of incomplete changeset is one in which I’ve created a new source file, but forgotten to hg add it. A “plain wrong” changeset is not as common, but no less annoying.
Rolling Back a Transaction
In Safe Operation, I mentioned that Mercurial treats each modification of a repository as a transaction. Every time you commit a changeset or pull changes from another repository, Mercurial remembers what you did. You can undo, or roll back, exactly one of these actions using the hg rollback command. (See Rolling Back Is Useless Once You’ve Pushed for an important caveat about the use of this command.)
Here’s a mistake that I often find myself making: committing a change in which I’ve created a new file, but forgotten to hg add it.
$
hg status
M a$
echo b > b
$
hg commit -m 'Add file b'
Looking at the output of hg status after the commit immediately ...
Get Mercurial: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.