1

Is there a way to convert a single commit (e.g. tip changeset in my local repository) to uncommitted changes in working directory?
I know that hg strip removes specified changeset(s) and backs it/them up, but does it convert those changesets to uncommited changes in working directory?

EDIT :

Concerning usage of hg rollback.

What if I have uncommitted changes before I want to do hg rollback? Do I have to commit those first? What about last several commits? Does sequential hg rollback stack up changes from those commits to existing uncommitted changes?

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
dragan.stepanovic
  • 2,955
  • 8
  • 37
  • 66

3 Answers3

7

If you're trying to redo the last commit (perhaps with a better commit message, perhaps with a bug fixed) then you should now use

$ hg commit --amend

to update the last commit. That is much safer than using hg rollback as described below.

If the commit is the last commit and you have not updated anywhere, then you can use hg rollback. Please read hg help rollback — is it a potentially destructive command.

What it does: hg rollback will roll back the last transaction in your repository. Every time you hg commit, hg pull, hg unbundle, etc, you create a new transaction. When everything is stored safely, Mercurial closes the transaction. If something goes wrong in the middle of the transaction, Mercurial can recover (see hg recover). You can also manually roll back the last transaction with hg rollback. See hg rollback --dry-run for a preview of what the command will do.

The rollback command wont touch your working copy. This means that files that showed up as modified before will appear modified again. So it's easy to do

$ hg commit -m "Fixed buug-123"

Ups, typo in the commit message! Let's fix that:

$ hg rollback
$ hg commit -m "Fixed bug-123"

(Use hg commit --amend instead with Mercurial 2.2 and later.)

The last commit message is also saved in .hg/last-message.txt so you can recover it from there if you don't have it in your shell history.

What if I have uncommited changes before I want to do hg rollback? Do I have to commit those first?

Rollback doesn't touch the working copy. This means that any additional changes in the working copy will appear together with the changes from the changeset. It's as if you didn't type hg commit at all.

What about last several commits? Does sequential hg rollback stack up changes from those commits to existing uncommited changes?

No, you only have one level of rollback since we only track the last transaction.

Community
  • 1
  • 1
Martin Geisler
  • 72,968
  • 25
  • 171
  • 229
  • What if I have uncommited changes before I want to do `hg rollback`? Do I have to commit those first? What about last several commits? Does sequential `hg rollback` stack up changes from those commits to existing uncommited changes? – dragan.stepanovic Jan 18 '12 at 10:16
  • Rollback doesn't touch the working copy. This means that any additional changes in the working copy will appear together with the changes from the changeset. It's as if you didn't type `hg commit` at all. Changing several commits is another topic, see [Rollback multiple commits](http://stackoverflow.com/q/4925094/110204) and maybe [Updating Commit Message](http://stackoverflow.com/a/8503002/110204). – Martin Geisler Jan 18 '12 at 10:36
  • It may be worth mentioning that in the specific case of wanting to fix a commit message, `hg commit --amend` is probably more useful. That was added in Mercurial 2.2, four and a half months after this answer was written. – Tom Anderson Apr 19 '13 at 09:44
  • @TomAnderson: Thanks, that's a great point! I've added a bit about `hg commit --amend` to the answer. – Martin Geisler Apr 22 '13 at 11:12
1

Any changeset (or set of changesets) more easy can be converted to local changes with Mercurial Queues (fold|unfold changeset)

TortoiseHG-centric manual (for old GUI) show operations step-by-step

Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
0

Although you should probably use hg commit --ammend when possible I now prefer the new and more powerful mecurial history editing feature: hg histedit especially if your familiar with git.

You can see what revision you want to go back by simply doing an hg out (ie you want to pick the revision that has not been pushed).

Adam Gent
  • 47,843
  • 23
  • 153
  • 203