How to abandon an uncommitted hg merge?
Asked Answered
O

5

138

I'm new to collaborating with Mercurial. My situation:

  • Another programmer changed rev 1 of a file to replace 4-space indents with 2-space indent. (I.e. changed every line.) Call that rev 2, pushed to the remote repo.
  • I've committed substantive changes rev 1 with various code changes in my local workspace. Call that rev 3.
  • I've hg pulled and hg merged without a clear idea of what was going on.
  • The conflicts are myriad and not really substantive.

So I really wish I'd changed my local repo to 2-space indents before merging; then the merge will be trivial (i'm supposing). But I can't seem to back up. I think I need to hg update -r 3 but it says abort: outstanding uncommitted merges.

How can I undo the merge, changes spacing in my local repo, and remerge?

Organon answered 3/4, 2010 at 2:58 Comment(0)
H
130

You can discard uncommitted changes with the -C (or --clean) flag:

hg update -C -r 3

BEWARE: Everything that was not committed will be gone!

After that you should probably use some kind of code formatter tool to do the entire operation, or at least some find and replace with regular expressions. Something as simple as replacing what matches ^____ (use 4 spaces instead of underscores) with __ (2 spaces), repeated a few times (unless you have insanely some nested code) should work.

Had answered 3/4, 2010 at 4:14 Comment(2)
Oh - thanks. You must have answered right about when I figured it out myself. I'm in emacs, so M-x indent-region did the reindent trick.Organon
Worth noting that untracked files will not be removed.Serow
H
141

BTW: if you just revert the merge you did and 3 is not your revision number you can do this:

hg update -C -r .
Hecto answered 1/6, 2010 at 11:23 Comment(2)
For anyone like me that at first didn't get how this works: the dot . is a shortcut to the previous revision.Vivid
@Thymine: From hg help update I get: If no changeset is specified, update to the tip of the current named branch... and tip might not always be your current revision you are working on. I did not test it, so far..Hecto
H
130

You can discard uncommitted changes with the -C (or --clean) flag:

hg update -C -r 3

BEWARE: Everything that was not committed will be gone!

After that you should probably use some kind of code formatter tool to do the entire operation, or at least some find and replace with regular expressions. Something as simple as replacing what matches ^____ (use 4 spaces instead of underscores) with __ (2 spaces), repeated a few times (unless you have insanely some nested code) should work.

Had answered 3/4, 2010 at 4:14 Comment(2)
Oh - thanks. You must have answered right about when I figured it out myself. I'm in emacs, so M-x indent-region did the reindent trick.Organon
Worth noting that untracked files will not be removed.Serow
A
39

To undo an uncommitted merge, use

hg update --clean

which will check out a clean copy of the original merge parent, losing all changes.

Amieeamiel answered 19/10, 2015 at 6:55 Comment(0)
O
2

I apparently just needed to hg update -C -r 3, which overwrites my local files with the rev in mind (which is what I thought hg update would do; but I was wrong.) Thanks for my help!

Organon answered 3/4, 2010 at 4:31 Comment(2)
Adding -C or --clean is how you tell Mercurial to go ahead, even when it will throw away some modified files. You're right that hg update -r X will normally take you to revision X, but when you are in a merge you need to insist a bit more :-)Reine
I think that "hg revert --all --cancelmerge" would be far more intuitive.Ilailaire
R
0

To undo an uncommitted merge you can use

hg update --clean

but Everything that was not committed will be gone! Even your all previous backup with hg shelve will also gone so avoid it if you have taken backup with hg shelve

Rotter answered 30/1 at 18:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.