3

I'm having a repository A with local changes which are very similar to the changes commited to repository B.

To keep things simple, lets say the local changes are in file a.

While in repository A, I pulled from repository B.

hg pull http://B_url:8000

And then I did, with local changes in the working directory

hg up

Please note the history is linear, hg heads contains only one tip, since I never committed anything to A. A has only local changes to the working directory.

Mercurial, as it should, warned about conflicts in file a. File a now contains the >>>> known signs for conflict.

I want to revert file a to the local version it had before the update. How can I do that with Mercurial? It's not in any revision now, it was just a local change.

flag
2 
Anton's suggestion of hg rollback is a good one, but this is a good case for committing changes locally often, even when things aren't working 100%. – Rob Sobers Aug 25 2010 at 14:03
@Rob Yep. Or, my other way of describing this situation: you can use Mercurial like Subversion, but Mercurial will then behave like Subversion. – Benjamin Pollack Aug 25 2010 at 14:44
@Rob, Benjamin. You don't want to commit half-work, but sometimes you need to pull something in order to finish your half work. I don't think that committing with message "source dump in order to merge with trunk" is a good idea. – Elazar Leibovich Aug 26 2010 at 13:54
@unknown, I agree that it's not the best idea to commit half-work, but it's much worse to pull something in your working directory which contains uncommited changes and loose some important data during the merge. Moreover you can use [rebase] Mercurial extension to collapse redundant changesets after successful merge. So your history will be clean. – Anton Moiseev Aug 26 2010 at 14:49
@Anton, thanks. But can I rollback from a commited half-work to my working directory? Something along the spirit of git stash. – Elazar Leibovich Aug 26 2010 at 18:04

1 Answer

4

Basically, you can't call hg up, if there are unmerged files in your working directory. The only way to update working directory is to call hg up with explicitly specified -c option, which discards all uncommitted changes. But in this case there shouldn't be any conflicted files.

So, I assume, that you has got this situation because of you have called hg merge explicitly, and you use merge tool that allows to save files with unresolved conflicts or you don't use any merge tool at all.

In any case, since it's just a local changes you can call hg rollback to rollback last Mercurial transaction (probably, it's merge operation in your case). Thus, all your merged files will be restored to the state, that they had before merging. Or if you rather satisfied with the rest merged files you can call hg revert /path/to/file/a to revert its state to the last committed version.

link|flag
You're assuming incorrectly. You can go hg pull and hg up even if your working directory is different from the tip. No hg merge is needed. – Elazar Leibovich Aug 25 2010 at 12:17
I don't contend that it's not possible to call [hg up] or [hg pull] from working directory whose parent is different from [tip]. But anyway, if you have unmerged files that can't be merged automatically or if you have unresolved conflicts in your working directory, [hg up] won't let you update directory without specifying [--clean] option. Please, try out advices from the last paragraph from my answer. It should work. – Anton Moiseev Aug 25 2010 at 13:16
I don't want to rollback all the files, just the specific file which had merge conflicts in it. I don't want the last committed version, I want the last committed version with local changes applied to it. – Elazar Leibovich Aug 26 2010 at 13:47

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.