Skip to Content
Mercurial: The Definitive Guide
book

Mercurial: The Definitive Guide

by Bryan O'Sullivan
June 2009
Beginner to intermediate
284 pages
8h 14m
English
O'Reilly Media, Inc.
Content preview from Mercurial: The Definitive Guide

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 ...

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

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Version Control with Subversion, 2nd Edition

Version Control with Subversion, 2nd Edition

C. Michael Pilato, Ben Collins-Sussman, Brian W. Fitzpatrick
HTTP/2 in Action

HTTP/2 in Action

Barry Pollard

Publisher Resources

ISBN: 9780596804756Errata Page