简体   繁体   中英

Can I merge multiple consecutive changesets into a changeset in Mercurial

Let's say I have changeset A, and I make changesets B1, B2, and B3 on top of A, while another developer makes changesets C1, C2, and C3 on top of A:

      B1 --- B2 --- B3
     /
--- A
     \
      C1 --- C2 --- C3

The other developer pushes his code to the central repository, and now I want to push my code, but I can't because there are multiple heads. I could rebase my changesets to go on top of his (and this is what I've been doing), but it would be more accurate to merge.

However, as far as I'm aware, I can only merge one changeset at a time. So I'd have to merge B1 onto C3 creating M1, and B2 onto M1 creating M2, and and B3 onto M2 creating M3. That's three merges I have to perform, and three new merge changesets cluttering up the repository! Is there a way that I can merge B1, B2, and B3 onto C3 all at once, or do I have to settle for modifying history using a rebase?

You can merge B3 and C3 to get:

      B1 --- B2 --- B3
     /                \
--- A                  M
     \                /
      C1 --- C2 --- C3

That is the traditional way to reconsile the two lines of development. The merge changeset will have two parents (merges always have two parents in Mercurial) B3 and C3, but you're still merging the combined effect of B1 to B3 with the combined effect of C1 to C3.

In fact, merges are only concerned with three states : A, B3, and C3. Since the state B3 include the changes you made in B1 and B2, you end up merging the changes in B1 to B3 into the state C3.

What you describe with three merges is actually what rebase does internally! After creating M1 to M3, it deletes the second parent of these merge commits and deletes B1 to B3. That leaves you with

--- A --- C1 --- C2 --- C3 --- M1 --- M2 --- M3

where Mi ~= Bi. As you note, this is a less accurate picture of what actually happened in the repository because you've linearized history what was really done in parallel.

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