Merge which should abandon one of the parents

Yuya Nishihara yuya at tcha.org
Sun Nov 18 03:31:45 UTC 2018


On Wed, 14 Nov 2018 16:21:59 +0100, Marcin Kasperski wrote:
> The situation:
> - there are two heads, say XXXX and YYYY
> - I want to merge them, but I want the resulting code to be
>   identical to XXXX
> 
> { That's fairly realistic case: YYYY was some experiment or sideline,
>   I am killing it for good, but I also mark that here and there
>   I reviewed it… }
> 
> So I read `hg help merge` and `hg help merge-tools`, and after some
> consideration (and especially after noticing difference between :local
> and :merge-local) I try:
> 
>    hg update XXXX
>    hg merge --tool :local  YYYY
> 
> I review the results, just to be sure:
> 
>    hg diff -r XXXX
> 
> … and, to my confusion, some differences show up. All files which were
> changed in YYYY, but untouched on XXXX, are changed.
> 
> After some consideration I guess that this is caused by the fact that
> merge tool is not spawned if changes are made only on one branch.
> Still, I am confused.
> 
> I work around this by
> 
>    hg revert -r XXXX --all
> 
> (plus hg rm of files created on YYYY branch) before commiting.

Yep, AFAIK merge followed by revert is the right tool to make a pseudo merge
discarding everything from p2. Since a merge tool runs per file to merge,
it can't reject nonconflicting files coming from p2.

> The problem is not new, see for example „crossed” section in
>    https://stackoverflow.com/questions/4197744/how-to-merge-to-get-rid-of-head-with-mercurial-command-line-like-i-can-do-with
> which also suggests that 
>    hg debugsetparents XXXX YYYY
> does exactly what I want.

Its outcome slightly differs from merge+revert since debugsetparents doesn't
create any merge nodes in file history (filelog). I don't know if that can
be a problem in real repository, but there's a bug report.

https://bz.mercurial-scm.org/show_bug.cgi?id=5973

> So mayhaps it could be possible to have 
>    hg merge --take-local
> or
>    hg merge --tool :local-only
> or sth similar to do exactly that (equivalent of debugsetparents)
> under more user-friendly umbrella?
> 
> Or at least, merge and mergetools help would benefit from some section
> mentioning this problem…

Perhaps "hg help merge -v" can have some examples to do a pseudo merge.



More information about the Mercurial mailing list