Newbie question: hg backout

Martin Geisler mg at daimi.au.dk
Wed Jun 11 04:01:38 CDT 2008


FP <fphg at mailinator.com> writes:

Hi!

> I'm reading through the hg book (the one at hgbook.red-bean.com),
> but I've hit a section where what happens on my PC (Vista + cygwin,
> Mercurial 1.0.1 from mercurial.berkwood.com) doesn't match the book.
> The code is section 9.3.1 to 9.3.3, reproduced below with the
> extraneous commands removed and quotes fixed for Windows:
>
> hg init myrepo
> cd myrepo
> echo first change >> myfile
> hg add myfile
> hg commit -m "first change"
> echo second change >> myfile
> hg commit -m "second change"
> echo third change >> myfile
> hg commit -m "third change"
> hg backout --merge -m "back out second change" 1
>
> This gives me the following error:
>
> reverting myfile
> created new head
> changeset 3:1110092ae73d backs out changeset 1:10f3768e4064
> merging with changeset 3:1110092ae73d
> merging myfile
> warning: conflicts during merge.
> merging myfile failed!
> 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
> There are unresolved merges, you can redo the full merge using:
>    hg update -C 2
>    hg merge 3

I get the same error, I use Mercurial under Linux.

> The book says the contents of myfile after the backout should be:
>
> first change
> third change
>
> So can someone tell me why the results differ and what if anything I
> need to change?

You're not doing anything wrong -- I think the book is being too
optimistic here :-)

> Also I barely understand the concept of merging (or VCS in general)
> but how is it even possible to get the result listed in the book?
> Even if I was manually merging how would I know which line to keep
> and which to discard (without refering back to the original patch)?

Yeah, and Mercurial also find it difficult :-) The changes are too
close to each other, and so the merging fails. I think this example
better illustrates a backout operation. First we create a base version
of the file:

echo " 1 \n 2 \n 3" > myfile
hg commit -m 'base'

Then we make two changes in each end of the file:

echo " changed 1st line \n 2 \n 3" > myfile
hg commit -m 'first change'
echo " changed 1st line \n 2 \n changed 3rd line" > myfile
hg commit -m 'second change'

The important thing is that the line with ' 2 ' stays constant since
this gives Mercurial a context for the merge:

hg backout --merge -m "back out first change" 1

It now works and you end up with

 1 
 2 
 changed 3rd line

as expected. If you look at the changes made a changeset with 'hg
diff' you will see that it simply adds and deletes lines. This is done
based on line numbers and on the context around the changed lines. And
in the example from the book the problem seems to be that there is not
enough context after the backout to unambiguously do the merge.

> p.s. I've looked at the other threads on this list and they seem to
> be on a much higher level than this one, so sorry if this question
> isn't appropriate here.

I think it's a good question and that it's very appropriate here!

-- 
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multi-Party Computation) to Python. See: http://viff.dk/.



More information about the Mercurial mailing list