1

Last night I started a merge; and forgot to commit it.

Later on I made some changes to the working copy.

Today I no longer want that merge at all (as I'll merge on a newer revision), but I want to keep the local working changes. The changes are independent of any merge resolution.

How can the local changes be kept (and/or reapplied later) while aborting the current merge?


Using shelve on the local changes was not allowed:

$ hg shelve foo/bar
abort: cannot shelve while merging

Using an hg up -C, the normal way to 'abort a merge', would eliminate the local changes.


This is not like How to 'hg merge' without affecting the working directory? because a merge has already been started, just not committed. Answers that involve finishing the commit first, and then picking changes is suitable if such can be shown simply, although the question is focused about 'abort without the commit'.

Community
  • 1
  • 1
user2864740
  • 60,010
  • 15
  • 145
  • 220
  • Could you export the changes you want to keep as patches? It'd potentially be a bit labour intensive I suppose. – Nanhydrin May 21 '16 at 14:45
  • @Nanhydrin I'm keen to any process that could be done while 'minimizing' tediousness of recovering in such cases. I found some magic to trick Hg to thinking it wasn't in the middle of a merge, but such seems like it should be kept as a magic trick :} – user2864740 May 21 '16 at 22:52

1 Answers1

3

The easiest solution is probably to record the changes temporarily in a secret commit and then to revert to that commit, e.g.:

hg resolve -m -a                       # mark all files as resolved
hg commit -s -m "Savepoint."           # Temporary commit.
hg update .^                           # Back to original revision.
                                       # (Use ".^" in cmd.exe on Windows.)
hg revert -r tip --all                 # Revert files to saved commit.
hg diff                                # Verify that you've got all the changes.
hg strip -r tip --keep                 # And discard the temporary commit.

We're using a secret commit here so that it doesn't accidentally get pushed if you forget to strip it (or if you plan to keep it around afterwards).

If you're using the evolve extension, hg prune -r tip is to be preferred over hg strip -r tip --keep, as it still keeps the temporary commit around (hidden) in case you need to refer to it later.

Reimer Behrends
  • 8,600
  • 15
  • 19