How to abandon a hg merge?

MercurialMerge

Mercurial Problem Overview


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?

Mercurial Solutions


Solution 1 - Mercurial

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

hg update -C -r .

Solution 2 - Mercurial

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.

Solution 3 - Mercurial

To undo an uncommitted merge, use

hg update --clean

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

Solution 4 - Mercurial

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!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGrumdrigView Question on Stackoverflow
Solution 1 - MercurialmathView Answer on Stackoverflow
Solution 2 - MercurialR. Martinho FernandesView Answer on Stackoverflow
Solution 3 - MercurialTaoView Answer on Stackoverflow
Solution 4 - MercurialGrumdrigView Answer on Stackoverflow