background preloader

Mercurial

Facebook Twitter

Chapter 9. Finding and fixing mistakes. Chapter 9.

Chapter 9. Finding and fixing mistakes

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.

I have the 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. Rolling back a transaction In the section called “Safe operation”, I mentioned that Mercurial treats each modification of a repository as a transaction. 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' $ hg status ?

$ hg add b$ hg commit -m 'Add file b, this time for real' Branch. Hg branch hg branches The term branch is sometimes used for slightly different concepts.

Branch

This may be confusing for new users of Mercurial. Branches occur if lines of development diverge. The term "branch" may thus refer to a "diverged line of development". Combining a line of development into an existing one is called merging . 1. Branching can happen by committing a changeset within a single repository or by committing diverging changes in distinct (but related) repositories. In contrast, merging — the act of combining two diverged development lines — can only be done in one repository. 1.1. Strictly speaking, a branch is created when a user creates a new changeset C2 in a repository R0, if its parent changeset P already has a child C1, thus adding a second child changeset C2 to that parent P. 1.2.

Note: after doing a hg --repository R1 pull --rev 3b978afa9ee5 R2 , repository R1 will look the same as repository R0. As such, each changeset in Mercurial forms an element of a branch. 2. 3. A Guide to Branching in Mercurial. I’ve been hanging out in the #mercurial and #bitbucket channels on freenode a lot lately, and I’ve noticed a topic that comes up a lot is “how does Mercurial‘s branching differ from git‘s branching?”

A Guide to Branching in Mercurial

#mercurial: A while ago Nick Quaranto and I were talking about Mercurial and git’s branching models on Twitter and I wrote out a quick longreply about the main differences. Since then I’ve pointed some git users toward that post and they seemed to like it, so I figured I’d turn it into something a bit more detailed. Nick Quaranto: longreply: Disclaimer: this post is not intended to be a guide to the commands used for working with Mercurial. Hg book: editing fail of all time: Prologue Before I start explaining the different branching models, here’s a simple repository I’ll use as an example: The repository is in the ~/src/test-project folder. For git users: each changeset in a Mercurial repository has a hash as an identifier, just like with git.

For now, ignore the default marker. Advantages. Hg Init: a Mercurial tutorial by Joel Spolsky.