简体   繁体   中英

How to merge after backout Mercurial

I did commit with merge, after that I did backout in main branch in order to revert last merge. After some time I need to merge branch, but mercurial says that abort: merging with a working directory ancestor has no effect

But in develop branch I don't see my changes from other branch.

Merge only picks up things that are new since the last merge. For instance:

default:   *------------?
            \          /
develop:     o--o--o--o

Each o represents some commit. We started with the default branch (named default ) with just one commit, the one marked * instead of o here. Then we made a develop branch starting with that same first commit, and did some work.

Once the work was ready, we went back to the default branch and used hg merge . This proposed making a new commit, ? . It did so by looking back to * —the commit that we had in common between default and develop —and looking at what we did on the two branches, and combining them.

We did nothing on default , so the combining was easy. Mercurial was able to just take everything we did on develop and put it all into default . Let's fill in the merge as a real commit now:

default:   o------------*
            \          /
develop:     o--o--o--o

Notice that I've moved the * . It's now the new merge. This is the most recent commit that links the two branches.

Meanwhile, hg backout makes a new commit that undoes a previous commit. Specifically you're asking to back out the merge. Let's draw that:

default:   o------------*--u
            \          /
develop:     o--o--o--o

This new commit is sort of like the antimatter version of the merge, in terms of changes made anyway. Everything in default goes back to the way it was before the merge. So I used the letter u (for "undo") instead of the usual round o dot for a more typical commit.

Where's the latest common commit on the two branches, though? The answer should be obvious: it's still * .

Now you ask Mercurial to merge again. It finds the changes in develop since the merge— and there aren't any . There is no new work to merge!

Suppose we check out develop again and make some new commits:

default:   o------------*--u
            \          /
develop:     o--o--o--o------o--o

Now we can hg merge develop into default again, to pick up the changes from the two new commits. But the changes you undid , with commit u (the backout commit), are still un-done. We'll only pick up the changes from the new (since the merge) commits on develop , and we keep the changes made (since the merge) on default , which is to say, the u undo changes:

default:   o------------o--u------*
            \          /         /
develop:     o--o--o--o------o--o

If you want all those changes back, you can simple back out the backout. That is, any time before or after adding the new commits on develop , and even before or after merging those new commits, you can undo the undo. Let's turn the u upside down into a "redo" and see how that looks, if we insert it before the next merge:

default:   o------------o--u--n-----*
            \          /           /
develop:     o--o--o--o--------o--o

In other words, commit u (the hg backout ) un-did the changes from the merge. It does not, and cannot, actually make the merge not happen . So to re-obtain the changes from the merge, you have to undo the undo, which is our n here.

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