How do I revert unresolved merges?

Simon King simon at simonking.org.uk
Thu Dec 4 17:08:39 UTC 2014


On Thu, Dec 4, 2014 at 4:04 PM, Brent Scriver <bscriver at phxlabs.ca> wrote:
>
> Hi all,
>
> I am working with Mercurial 3.2.1 and I'm running experiments with it to get
> familiar with the work flow, primarily for merging changes from different
> repositories as we use a number of third party tools (with occasional custom
> edits).
>
> I encountered a scenario I couldn't easily identify a way to back out of.
> Given repository A & B and having done a pull -f of B into A, I want to
> merge subsequent changes.

[side note: the "-f" flag to "hg pull" means "force", and it is only
necessary if you are pulling the history of a completely unrelated
repository into your own, which should be a very rare occurrence. Are
the source repositories that you are trying to merge completely
unrelated?]

>
> It looks like until I complete the merge, hg revert will only revert changes
> that have been resolved.  How do I revert those that are not resolved (and
> the entire merge altogether as if the pull request hasn't happened)?
>

The help for "hg merge" says:

    To undo an uncommitted merge, use "hg update --clean ." which will check
    out a clean copy of the original merge parent, losing all changes.

To explain a bit further, when you have started a merge, but before
you commit, your working copy has 2 parents (the 2 revisions that you
are merging). To give up on the merge, you simply "hg update" to a
different revision. "." represents the first parent of your working
copy, which is the revision you were at before you started the merge,
and "--clean" tells it to discard any uncommitted changes.

I'm not sure I understand what you are saying about "hg revert" - I
wasn't aware that it had any dependence on whether or not a merged
file was resolved. Could you give an example?

(The note about cancelling an uncommitted merge also appears in the
help for "hg revert" as well, by the way)

> The only guaranteed solution I could find was to delete my local of A and
> re-clone it (making it very important that all pending changes in the
> working copy have been pushed back).
>
> Recommendations?

Recloning definitely shouldn't be necessary. Even if you wanted to
start the merge over, you should only need to:

  hg update --clean .
  hg merge

>
> Thank you,
> Brent Scriver
>

Hope that helps,

Simon



More information about the Mercurial mailing list