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 statusM a$echo b > b$hg commit -m 'Add file b'
Looking at the output of hg status after the commit immediately ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access