简体   繁体   中英

“nothing to merge” with hg merge

I'm trying to convert from a different DVCS to Mercurial. I've found a situation where Mercurial won't let me do something that the other DVCS finds perfectly reasonable.

It seems that in the repo, one of the users is in the habit of working like this:

  • fork
  • do work in fork
  • merge trunk -> fork
  • test
  • merge fork -> trunk

That all seems perfectly reasonable. Except that if trunk hasn't advanced while the user was testing, hg refuses to do the final merge, with

abort: nothing to merge

and --force doesn't help.

I can replicate this with the following test case:

echo "Test data" > file
hg add file
hg commit file -m "Ancestor"
# rev 0

echo "Trunk" > file
hg commit file -m "Trunk"
# rev 1

hg checkout 0
echo "Branch" > file
hg commit file -m "Branch"
# rev 2

hg merge --tool internal:local 1
hg commit -m "Merge trunk to branch"
# rev 3

hg checkout 1
hg merge --tool internal:local 3  # <--- fails
hg commit -m "Merge branch to trunk"

If I modify the test so that trunk advances between the two merges, so at the final merge trunk is now a new revision 4 and revision 3 is merged into it, everything works fine.

This is obviously all perfectly standard workflow --- I do this myself. So why isn't this working?

This test case works:

echo "Test data" > file
hg add file
hg commit file -m "Ancestor"
hg branch trunk
# rev 0

echo "Trunk" > file
hg commit file -m "Trunk"
# rev 1

hg checkout 0
hg branch branch
echo "Branch" > file

hg commit file -m "Branch"
# rev 2

hg merge --tool internal:local 1
hg commit -m "Merge trunk to branch"
# rev 3

hg checkout 1
hg merge --tool internal:local 3
hg commit -m "Merge branch to trunk"

This is exactly the same code as the first test case, except that trunk and fork are now explicitly branched rather than just using ad-hoc heads. All merges and checkouts use the same revisions as before. Apparently branches are magic.

Unfortunately I can't use branches in the real code, because the other DVCS is using ad-hoc heads, none of which have any branch information. I don't want to have to fake a branch for every fork.

How can I persuade Mercurial to let me do this without using explicit branches?

Revision 3 is a direct ancestors of revision 1. There is no concurrent changes to merge here. All you need to do is hg update 3 .

Merge apply when you have two diverging branches and you want to gather changes of both side in a new common version. In that case you need a three way merge between the two divergent version (using information from they greater common ancestors)

In you case there is two divergent version, no common ancestors, just an old version and new version of your file. You just want to use hg update ( update is the official command for moving around, checkout is an alias to it)

I don't know why this other DVCS confused you by calling "merge" something that does not involves any merging.

(note: consider using hg log -G for a graphical output of your graph)

(other note: never use merge --force this is a old deprecated flag doing silly things. It is hidden from hg help merge for good reason)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM