1
votes

This is basically the same question as Temporarily switch working copy to a specific Git commit, but for Mercurial.

Say revision 500 is the last revision I've committed in Mercurial. I've worked some more, and realized something went wrong in an earlier revision. So, I've "git stashed", that is, hg shelved my current changes, so I am at a clean revision 500.

Now what I want to do is checkout revision 499, rebuild software, see if it still has error; if it does, checkout revision 498, rebuild software, see if it still has error; if it does, revision 497, rebuild software, see if it still has error; etc etc until I figure out which revision introduced the error.

Once I'm done with that, I want to go back to revision 500, unshelve my previous work, add to that a fix, and then make a new commit (which would be revision 501). That means when I go back in history I don't want to reset anything, nor stage anything from there.

In git I can just do git checkout HASH to go back in history, and once done, git checkout master to go back to the tip. Which commands should I use in Mercurial?

1

1 Answers

3
votes

You can go to older revisions using hg update:

hg update 499  # The short id number or the full hash

or alternatively if you want to step to the parent changeset without needing to know the id, you can use a mercurial revset:

hg update .~1

once you have identified your issue you can simply:

hg update tip

and unshelve your changes, add your fix and commit.

I recommend you read the Mercurial: The Definitive Guide. Your question very basic / entry level mercurial usage.

Edit: the link to Mercurial: Definitive Guide is:

http://hgbook.red-bean.com/read/

or the 1.9 version of the boook:

https://book.mercurial-scm.org/read/index.html